Git pull = Git fetch + Git merge.
git pull origin master
Let's say you are on local/master, and run this command, git will fetch commits from origin/master and then merge it into local/master.
git pull
This is a shorthand for pulling commits into local branch that is tracking a remote branch.
And that brings the question, how does one make a local branch track a remote branch.
As far as I know, there are two common ways to do so:
1. When pushing for the first time:
git push -u origin branch_name
The -u
flag tells git to make the local branch track the remote branch.
- When creating a local branch for an existing remote branch:
git branch --track branch_name origin/branch_name