Reputation: 8700
I've accidentally unhitched my master branch from tracking origin master I think. It used to be that I could run git pull
and git push
and it would know that I meant git push origin master
but now it does not, and I think it's tracking a different branch because git push origin master
works fine (everything up to date) and git push
tells me it can't fast-forward changes.
Here's what my git branch -a
looks like:
ianstormtaylor:nib Storm$ git branch -a
* master
original
transforms
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/sizing
remotes/origin/transforms
Not sure if that remotes/origin/HEAD -> origin/master
is the part that is messed up.
I think this all resulted from a git merge origin sizing
call when i meant to do git merge sizing
(while on master).
Anyone know what's going on and is able to help? I'd just like to get back to the default remote-tracking setup that git clone
creates.
Upvotes: 6
Views: 5041
Reputation: 1490
You can use
git branch --set-upstream my_branch origin/my_branch
Alternatively
git push -u origin my_branch
See Git: Why do I need to do --set-upstream
all the time? for more detail.
Upvotes: 2
Reputation: 301337
All you need in you git config (do git config -e
to edit) is the following:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = /Users/me/test.git
[branch "master"]
remote = origin
merge = refs/heads/master
If it is there, git push
from master, will be equivalent to git push origin master
The remotes/origin/HEAD -> origin/master
part just says that HEAD of remote origin is master branch ( of origin) and is fine.
Upvotes: 5
Reputation: 393537
I suppose you could edit the .git/config file or set the config using
git config branch.master.remote origin
git config branch.master.merge refs/heads/master
Alternatively, recreate the master branch using the -t
(--tracking
) option
Both should result in a section similar to this in your .git/config
:
[branch "master"]
remote = origin
merge = refs/heads/master
Upvotes: 1
Reputation: 32377
I've had this happen a few times - and while I'm not sure of the exact cause I don't believe it's from a mistake that you've made. Rather it's simply that git pull is a shortcut to the most recent remote branch and it's forgotten what the most recent branch is.
Executing a git pull origin master
usually updates the setting and resets everything.
Upvotes: 1