David Sempsrott
David Sempsrott

Reputation: 113

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.

Upvotes: 1

Views: 795

Answers (2)

ggg
ggg

Reputation: 86

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.

Upvotes: 2

Aaron Morefield
Aaron Morefield

Reputation: 995

So tracking branch is the branch which your branch is working actively off of. Take the follown

__________master_________________
    \_____staging(Most recent pushed branch)____
         \_______newFeature (New branch, local)________

You have created the new feature locally, but do not have a branch on your remote for the new feature. Currently your upstream would be staging, since that is what your most recent branch would have been.

If you push up your newFeature branch, other users can access it, but it is not by default your tracked branch (i.e. if you run git pull you will, be receiving everyone's changes from staging). However, when you set the tracking branch to be your newly pushed branch, any changes added to your new feature branch will be the default that is pulled in. You can always merge staging in (git merge -b staging) to your feature branch to keep it up to date.

Essentially it is self-descriptive: what remote branch do you want your local branch following most closely: that is the branch you track.

Upvotes: 0

Related Questions