Search code examples
gitgit-branchgit-push

In Git, what does it actually mean to push a local branch without tracking the corresponding remote?


I’ve read that in Git if you want to push a local branch to the remote server and make the local branch track the remote, you can use git push -u mybranch remoteserver/mybranch. I suppose that means if I use git push without the -u option then it will push the branch but not track it. But what does “push without tracking” actually mean? What will I miss out on if I forget the tracking part? I realize if you just forgot, you can always establish the tracking relationship after the fact by using git branch -u. My point is, why is there a difference?

I’ve read the Pro Git book (excellent BTW) and searched all kinds of questions, and everybody talks about how to set up tracking branches, but nobody discusses what would be the result of pushing a local branch without tracking, and why such a thing would ever be useful.


Solution

  • What will I miss out on if I forget the tracking part?

    You miss little stats to see immediately if you have to push or pull commits to/from the remote part.

    git status output example with tracking

    $ git status
    On branch mybranch
    Your branch is ahead of 'origin/mybranch' by 2 commits.
      (use "git push" to publish your local commits)
    
    nothing to commit, working tree clean
    

    git status output example without tracking

    $ git status
    On branch mybranch
    nothing to commit, working tree clean
    

    You also miss the ability to push simply with git push and pull simply with git pull (after the first push you do with git push -u remoteserver mybranch, of course).

    I don't get anything else at the moment, but if git has others hints he can get you (knowing that you want mybranch "in sync" with origin/mybranch) you'll probably miss them.