Sharanbr
Sharanbr

Reputation: 365

Git - pushing local branch to remote

I have created a local branch, added few files and pushed them onto remote. When I pushed my changes for the first time, I used: git push origin test1 - where test1 is the name of my branch. Hereafter, I have made additional changes and just doing git push. Do I need to do specify remote name every time I push or that is set-up after the first time I do push?

Also, when I do git branch -vv, I see the following:

  master 6727062 [origin/master] ..
  test   c745cca ..
* test1  4bd622d ..
  testx  2fbfdfc ..

I was expecting test1 branch to track remote test1 but I don't see that here.

What Am I missing?

Upvotes: 1

Views: 11062

Answers (3)

Mad Physicist
Mad Physicist

Reputation: 114310

You can set up git branches to push and pull from different remote branches. If you want to set up tracking, you need to do it explicitly. There are a few ways to do this.

  1. Specify -u/--set-upstream as an argument to git push.

    git push -u origin test1
    

    You should not need to specify a remote for push or pull after that unless you want to use a different remote. git push test1 will always push to origin. You can still use git push upstream test1 if you want to push to a different remote though.

  2. Specify -t/--tracking to git checkout after you have made your initial push:

    git checkout -t origin/test1
    

    The name of the local branch is optional in this case since you intend to keep the same name as the remote.

  3. Manually set up the remote tracking using git branch -u/--set-upstream:

    git branch -u test1 origin/test1
    

You can find more details in this excellent answer: https://stackoverflow.com/a/10002469/2988730

Upvotes: 3

Vampire
Vampire

Reputation: 38639

If you push with -u (a.k.a. --set-upstream) the tracking is configured like you expect. If not, then not. You can either set this up on next push, or use git branch --set-upstream-to=test1 test1.

Upvotes: 0

Bhagyashri
Bhagyashri

Reputation: 1

You need to checkout your test1 branch first in order to push changes to it.

use this command..

git checkout <branch name>

in your case,

git checkout test1

Upvotes: -2

Related Questions