I know how to make a new branch that tracks remote branches, but how do I make an existing branch track a remote branch?
I know I can just edit the .git/config
file, but it seems there should be an easier way.
I know how to make a new branch that tracks remote branches, but how do I make an existing branch track a remote branch?
I know I can just edit the .git/config
file, but it seems there should be an easier way.
In a somewhat related way I was trying to add a remote tracking branch to an existing branch, but did not have access to that remote repository on the system where I wanted to add that remote tracking branch on (because I frequently export a copy of this repo via sneakernet to another system that has the access to push to that remote). I found that there was no way to force adding a remote branch on the local that hadn't been fetched yet (so local did not know that the branch existed on the remote and I would get the error:
the requested upstream branch 'origin/remotebranchname' does not exist
).In the end I managed to add the new, previously unknown remote branch (without fetching) by adding a new head file at
.git/refs/remotes/origin/remotebranchname
and then copying the ref (eyeballing was quickest, lame as it was ;-) from the system with access to the origin repo to the workstation (with the local repo where I was adding the remote branch on).Once that was done, I could then use
git branch --set-upstream-to=origin/remotebranchname