I am working on a local branch (feature1) created from mainline branch. I would like to push this local branch to remote repository. How to achieve this in git along with tracking option.
Asked
Active
Viewed 7,719 times
2 Answers
11
Push with the -u option:
git push -u origin <branch>
-u, short for --set-upstream, that is set the upstream in origin to the <branch> name. If you omit the branch name, the local branch name is used instead. Full story on Git's documentation.
Eric Platon
- 9,266
- 6
- 40
- 47
Dave Grabowski
- 1,579
- 7
- 18
-
That’s assuming “origin” is the name of the OPs remote… – Raphael Schweikert Sep 13 '16 at 06:10
0
You would have created a feature branch from mainstream branch by
git checkout -b <branch>
So you can push this local branch to server by using below command. -u option is to set the upstream for your branch.
git push -u origin <branch>
This will push the local branch to remote.
Going forward, keep on add/edit the files in this branch and commit
git add <file>
git commit -m "message to commit"
then just push your changes, without -u option.
git push origin <branch>
Sanjay Bharwani
- 2,151
- 25
- 28
-
After the initial use of `-u`, a simple `git push` would suffice (without the `«remotename» «branchname»` suffix). – Raphael Schweikert Sep 13 '16 at 06:11