One way to add a new branch to the remote repository is to first add the branch to your local repository and then push that local branch to the remote repository.
Let’s see what branches we have now:
git branch
We have just one branch. Not much to shake a stick at. So create a new branch named v0:
git branch v0
Then push the new branch named v0 to the remote repository named origin. The git push syntax is: git push [remote-repository-name] [branch-or-commit-name]:
git push origin v0
Currently the master and v0 branches are identical, but they will diverge (the whole point of branches is to diverge) as users make different commits to each branch.
The person who created the branch has more configuration to do to make their local v0 branch configured correctly. This, configures git to automatically pull/fetch from the new remote v0 branch, without having to specify the v0 repository and branch name every time using git pull or git fetch.
git branch --set-upstream v0 origin/v0
Branch v0 set up to track remote branch v0 from origin. That does the job, and from now on, all creator has to type is:
git pull
-------------------------------------
Tracking The New Branch: Other Devs
When other devs git clone the shared repository, the git clone command will automatically:
- Create the a new local branch named v0
- Configure their local repository to correctly track changes in the new v0 branch. For example, when the users are on the new local v0 branch, The user can type git fetch, git pull, and git push without specifying the origin remote andv0 branch with every command.
The next time devs retrieves the latest commits from the shared repository, they will see the new v0 branch automatically created locally:
git pull
Devs can then switch to the new branch:
git checkout v0
Devs can then commit to the new branch:
git commit -a –m “added a new line to”
Devs can then commit to the remote branch:
git push