How to use Git with GitHub.

Table of Contents

Here’s a simple blog post on


Getting Started with Git and GitHub

Git is a powerful version control system that helps track changes in your code. GitHub allows you to store your projects remotely, collaborate with others, and manage versions effectively. This guide will help you get started with Git and GitHub.


1. Initializing a Git Repository

To start tracking your project with Git, navigate to your project folder and initialize a repository:

cd my-project
git init

This creates a hidden .git folder, making it a Git repository.


2. Tracking and Committing Files

After making changes, add them to Git’s staging area:

git add .

Or add specific files:

git add filename.txt

Next, commit your changes with a message:

git commit -m "Initial commit"

3. Configuring Git User Details

Set up your Git username and email (used for commits):

git config --global user.name "Your Name"
git config --global user.email "[email protected]"

4. Cloning a GitHub Repository

To download an existing GitHub repository:

git clone <repo-url>

5. Checking Repository Status

View the current status of your files:

git status

Check the remote repository URL:

git remote -v

6. Syncing with GitHub

To fetch updates from GitHub without applying them:

git fetch origin

To fetch and merge updates:

git pull origin main

To push local changes to GitHub:

git push origin main

7. Working with Branches

To create and switch to a new branch:

git checkout -b new-feature

To list all branches:

git branch

To switch to another branch:

git checkout main

For newer versions of Git:

git switch main

8. Merging Branches

To merge a feature branch into the main branch:

git checkout main
git merge new-feature

If conflicts arise, resolve them manually, then:

git add .
git commit -m "Resolved merge conflicts"

  1. Push your branch to GitHub:

    git push origin new-feature
    
  2. On GitHub, go to the Pull Requests tab.

  3. Click “New pull request”.

  4. Select the source and target branches.

  5. Click “Create pull request” and merge after approval.


Conclusion

This guide covered the basics of Git and GitHub to help you track changes, collaborate, and manage versions efficiently.

Related Posts

How to use Git with GitHub.

Here’s a simple blog post on Getting Started with Git and GitHub Git is a powerful version control system that helps track changes in your code. GitHub allows you to store your projects remotely, collaborate with others, and manage versions effectively. This guide will help you get started with Git and GitHub.

Read More