Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When i push a local branch up to the server it doesn't show as tracking

Tags:

git

I have a git repo. If I create a local branch, do stuff and then push the branch up to the server, doing a git branch -vv doesn't show it as tracking.

If however I pull the repo down fresh, it does show up with git branch -vv

I've also tried the following without success.

git config --get branch.foobranch.remote

git config --get branch.foobranch.merge

If I continue to use that branch, doing multiple push and pulls from the server, everything works so I can only assume that git knows that the branch is tracking the remote somehow. I'd like to know how I can access this information.

like image 665
Razor Avatar asked Oct 20 '16 04:10

Razor


People also ask

Why there is no tracking information for the current branch?

The “There is no tracking information for the current branch.” occurs when Git doesn't know which branch on the server it should pull from. Almost always you want to pull from the branch on the server origin with the same name as your local branch ( mybranch ).

How do I know which branch is tracking?

There is a command that gives you about all tracking branches. And to know about the pull and push configuration per branch you can use the command git remote show origin. and you can use -sb option for seeing the upstream. Hope this information will help you to find which branch is tracking.

How do I create a local branch to track a remote?

To create a new local branch based on a remote branch, use the "-track" option in the branch command. You can also do this by using the "checkout" command. If you want your local branch to have the same name as the remote branch, you only need to specify the name of the remote branch.

How do you set upstream for a branch?

The easiest way to set the upstream branch is to use the “git push” command with the “-u” option for upstream branch. Alternatively, you can use the “–set-upstream” option that is equivalent to the “-u” option.


1 Answers

But isn't that tracking information there to begin with?

No: when you create a new branch locally, Git won't assume where (to which remote repo) you want to push it.

More specifically, a simple git push (without the -u) won't set the local config branch.<name>.remote and branch.<name>.merge, which are set when a local branch has one upstream branch associated to it.

You have to specify the upstream repo the first time you will push that branch.

That differs from a git clone (man page):

Clones a repository into a newly created directory, creates remote-tracking branches for each branch in the cloned repository (visible using git branch -r), and creates and checks out an initial branch that is forked from the cloned repository’s currently active branch.

Since a remote tracking branch exist for (for instance) origin/master, when git clone does checkout master, said master will automatically be associated with its upstream branch origin/master.
See git checkout

If <branch> is not found but there does exist a tracking branch in exactly one remote (call it <remote>) with a matching name, treat as equivalent to

$ git checkout -b <branch> --track <remote>/<branch>

That is why you can directly push from master after a clone, but you cannot push directly after creating a new branch (for which there is no origin/newBranch remote tracking branch already present in your local repo)

That checkout (tracking automatically the existing remote tracking branch origin/<branch>) will set the local config branch.<name>.remote and branch.<name>.merge.

like image 124
VonC Avatar answered Sep 28 '22 12:09

VonC