Git-Distributed Version Control System part-4

Git-Distributed Version Control System part-4

Git-Distributed Version Control System part-4

Git-Distributed Version Control System part-4

Continue learning Git-Distributed Version Control System part-4 in this advanced guide. Explore branching, merging, and squashing with real-world Git workflow examples.

 Git – git sync with Github (pull,fetch,merge,push)

Git Sync with GitHub

To sync your local repository with GitHub, you use commands that help you:

  • Download changes from GitHub → your local machine

  • Upload your local changes → GitHub

The key commands are:

CommandDirectionPurpose
git fetchGitHub → LocalGets changes from remote, does not merge
git pullGitHub → LocalGets changes and merges them into your branch
git mergeLocal onlyMerges one branch into another
git pushLocal → GitHubSends your local commits to GitHub
 

1. git fetch

bash
git fetch origin
  • Downloads the latest changes from the remote (GitHub).

  • Does not merge them automatically.

  • Useful when you want to review changes before merging.

2. git pull

bash
git pull origin main
  • Combines fetch + merge.

  • Fetches changes from GitHub and automatically merges into your current local branch.

  • If conflicts occur, Git will ask you to resolve them manually.

3. git merge

bash
git merge origin/main
  • Used to manually merge changes from one branch into another.

  • Useful after git fetch when you want full control of when to merge.

4. git push

bash
git push origin main
  • Uploads your local commits to GitHub.

  • Others will then see your updates on the GitHub repository.

Typical Sync Workflow:

  1. Check your status:

    bash
     
    git status
  2.  Fetch latest changes from GitHub:

    bash
     
    git fetch origin
  3.  Merge those changes into your branch:

    bash
     
    git merge origin/main

    Or just pull directly:

    bash
     
    git pull origin main
  4. Make your changes, stage and commit:

    bash
     
    git add .
    git commit -m "Your message"
  5.  Push your changes to GitHub:

    bash
     
    git push origin main

Summary Chart

ActionCommand
Download changes onlygit fetch origin
Download & merge changesgit pull origin branchname
Combine branches locallygit merge branchname
Upload changes to GitHubgit push origin branchname

 Git-Distributed Version Control System part-3

Previous

 Git-Distributed Version Control System part-5

Next