1

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?

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
Sharanbr
  • 345
  • 1
  • 5
  • 18
  • 1
    Possible duplicate of [Make an existing Git branch track a remote branch?](http://stackoverflow.com/questions/520650/make-an-existing-git-branch-track-a-remote-branch) – Mad Physicist Feb 07 '17 at 18:44

3 Answers3

3

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

Community
  • 1
  • 1
Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
  • thanks. but I see that git push going through fine. So, where are these commits landing up on remote? – Sharanbr Feb 07 '17 at 18:29
  • @Sharanbr. The issue is not that your push is not working. It's that your local branch is not configured to push and pull to a specific remote branch. The -u flag sets that up for you so you don't have to write the whole thing out manually and you see the result in `git branch -vv` – Mad Physicist Feb 07 '17 at 18:34
0

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.

Vampire
  • 35,631
  • 4
  • 76
  • 102
-2

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
Maytham Fahmi
  • 31,138
  • 14
  • 118
  • 137
  • That's not correct. You can push any commit-ish to any remote branch, no matter what you have checked out locally. – Vampire Feb 07 '17 at 18:30
  • That is not true. You can push to any remote branch from any local branch at any time. The only thing checkout can help you with is setting up tracking, but OP is already past that step. – Mad Physicist Feb 07 '17 at 18:30