When you are working on a remote repository (say, GitHub) with someone else, you will at some point want to share your changes with them. Once they have pushed their changes to a remote repository, you can retrieve those changes by pulling from this repository.
git pull
Will do it, in the majority of cases.
You can pull changes from a different remote or branch by specifying their names
git pull origin feature-A
Will pull the branch feature-A
form origin
into your local branch. Note that you can directly supply an URL instead of a remote name, and an object name such as a commit SHA instead of a branch name.
To imitate the behavior of a git pull, you can use git fetch
then git merge
git fetch origin # retrieve objects and update refs from origin
git merge origin/feature-A # actually perform the merge
This can give you more control, and allows you to inspect the remote branch before merging it. Indeed, after fetching, you can see the remote branches with git branch -a
, and check them out with
git checkout -b local-branch-name origin/feature-A # checkout the remote branch
# inspect the branch, make commits, squash, ammend or whatever
git checkout merging-branches # moving to the destination branch
git merge local-branch-name # performing the merge
This can be very handy when processing pull requests.