Git Basics: How to retrieve from remote repository using Git fetch/pull?

In the last article, we discussed about "Git Tags". Today we are going to discuss another topic "Git Fetch" and "Git Pull", which I hope, will help you to easily work with Git Bash commands to download code from repository.


Let's continue learning about "git fetch" and "git pull" today with the commands that you need to know. Stay tuned to read more and more posts on this topic.


$ git fetch, $ git pull commands (

$ git fetch

The "git fetch" command imports commits from a remote repository to your local. The resulting commits are stored as remote branches instead of the normal local branches. This gives you chance to review the changes before integrating them.


Fetching is generally done when you want to see other's changes. As fetched content is represented as a remote branch, it has actually no effect on your local dev branch.


Fetch all branches from remote repository:

$ git fetch <remote>


Fetch from a specific remote branch:

$ git fetch <remote> <branch>


Fetch all tags from the remote:

$ git fetch -t

$ git pull

Merging the upstream changes into your local repository is a common task in Git based workflows. The "git pull" command does the same thing that you do with the commands "git fetch" and "git merge" together. That means, it fetches the specified remote’s copy of the current branch and immediately merges it into the local copy. It’s an easy way to synchronize your local repository with upstream changes.


Pull from remote repository:

$ git pull <remote>


Pull from remote via rebase:

$ git pull --rebase <remote>


The --rebase option can be used to ensure a linear history by preventing unnecessary merge commits. Many developers prefer rebasing over merging, as it puts the changes on top of other's changes.


Was this post useful? If you came to this page by searching online about git basics, please have a look into my other blog posts. Subscribe to the RSS feed or the email newsletter to keep yourself updated.




If you have come this far, it means that you liked what you are reading. Why not reach little more and connect with me directly on Twitter , Facebook , Google+ and LinkedIn . I would love to hear your thoughts and opinions on my articles directly. Also, don't forget to share your views and/or feedback in the comment section below.


  1. Trying to move beyond the basic basics and I keep coming across fetch and I'm having a bit of difficulty fitting it into a workflow. You mention that I can then see the changes others made. What is the best or typical way of viewing those changes locally? If I open up a code editor it will be the local branch. I just tried it for a project I look into every once in a while, and I'm seeing that I'm 39 commits behind. But don't know what is in those 39 commits. Thanks in advance.


© 2008-2016 - Microsoft Technology Blog for developers and consumers | Designed by Kunal Chowdhury
Back to top