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 8,083 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,819
- 6
- 41
- 48

Dave Grabowski
- 1,619
- 10
- 19
-
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
- 3,317
- 34
- 31
-
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