0

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.

  • 2
    Does this answer your question? [What is a tracking branch?](https://stackoverflow.com/questions/4693588/what-is-a-tracking-branch) – mkrieger1 Jan 21 '21 at 21:26
  • @mkrieger1 thanks but no it doesn’t fully answer my question. Like many other sources I’ve read, it talks a lot about what a tracking branch is and how to create one, but doesn’t explain why pushing a local branch to a remote tree doesn’t automatically make it a tracking branch — which is incredibly counterintuitive to me. – David Sempsrott Feb 06 '21 at 01:22

2 Answers2

0

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.

Aaron Morefield
  • 923
  • 10
  • 17
0

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.

ggg
  • 66
  • 4
  • OK thanks that’s helpful. It’s still a mystery to me why making it a tracking branch isn’t the default behavior of `git push` when you’re pushing to a branch with the exact same name on the remote…seems like that would be the intent 99.9% of the time. But maybe that’s just my inexperience. – David Sempsrott Feb 06 '21 at 01:33
  • I think you can configure this behaviour, try to see here https://stackoverflow.com/questions/948354/default-behavior-of-git-push-without-a-branch-specified – ggg Feb 08 '21 at 10:52