Question

i wanted to setup my local mainline branch to track origin/mainline but used the command

git branch --set-upstream origin/mainline mainline by mistake,

with the outcome Branch origin/mainline set up to track local branch mainline.

How can I fix this so local mainline tracks remote mainline?

Was it helpful?

Solution

You have the wrong arguments order, what you want is git branch --set-upstream mainline origin/mainline.

see:

-t, --track

When creating a new branch, set up configuration to mark the start-point branch as "upstream" from the new branch. This configuration will tell git to show the relationship between the two branches in git status and git branch -v. Furthermore, it directs git pull without arguments to pull from the upstream when the new branch is checked out.

This behavior is the default when the start point is a remote-tracking branch. Set the branch.autosetupmerge configuration variable to false if you want git checkout and git branch to always behave as if --no-track were given. Set it to always if you want this behavior when the start-point is either a local or remote-tracking branch.

--set-upstream

If specified branch does not exist yet or if --force has been given, acts exactly like --track. Otherwise sets up configuration like --track would when creating the branch, except that where branch points to is not changed.

So what your had did is creating a local branch named origin/mainline which tracks mainline branch.

OTHER TIPS

It seems git created another local branch origin/mainline and made it to track mainline. I used git config -e and then set remote=origin for mainline(origin being already defined) and then git branch -d origin/mainline to delete the local branch. Seems to have addressed the issue.

I ran into the similar problem of using:

git branch -t origin/master

instead of git branch --set-upstream-to=origin/master to track origin/master.

Somewhat simpler solution was: I have deleted ****local branch** Origin/master** that was created first.

And then did: git branch --set-upstream-to=origin/master succeed, because now it can detect the actual origin/master.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top