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
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.
$ git fetch <remote>
$ git fetch <remote> <branch>
$ 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.
$ git pull <remote>
$ 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.