12

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.

Sunil
  • 856
  • 12
  • 24

2 Answers2

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
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