Reputation: 12405
Our repo happens to have a tag that has the same name as the branch name. So when I try to pull from that branch, git confused and pulled from tag, like this. I have to delete that tag first to make my git pull work.
So how do I tell git pull from branch not from tag ?
cc-backend ➤ git pull origin 0.9.0-rc6-patch1
From 10.0.0.28:webcc/cc-backend
* tag 0.9.0-rc6-patch1 -> FETCH_HEAD
Already up to date.
/* I have to delete that tag and git pull again to get the result I want */
cc-backend ➤ git pull origin 0.9.0-rc6-patch1
From 10.0.0.28:webcc/cc-backend
* branch 0.9.0-rc6-patch1 -> FETCH_HEAD
Updating 9d7e9dc3..2bf3f96a
Fast-forward
app/Services/GroupSeat/Seat.php | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
Upvotes: 15
Views: 6838
Reputation: 30868
It seems the remote repository has a tag and a branch with the same name 0.9.0-rc6-patch1
. Use the full name to fetch/pull,
# fetch/pull the tag
git fetch/pull origin refs/tags/0.9.0-rc6-patch1
# fetch/pull the branch
git fetch/pull origin refs/heads/0.9.0-rc6-patch1
There could be other refs. According to my personal experience, a Gerrit user may push and create an unexpected ref in a Gitlab repository by mistakenly following the Gerrit push syntax git push origin HEAD:refs/for/master
. refs/for/master
is a client magic ref. After receiving this push, Gerrit converts it into a pending change ref like refs/changes/11/2311/1
in the server side and binds it with the target branch master
. When this change is approved, this ref will be merged into refs/heads/master
. However, Gitlab simply creates a meaningless ref refs/for/master
. In some cases, later the user may fail to update the local master branch with the head always pointing to an older commit, although the git pull
command succeeds.
If you encounter this abnormal behavior, use git ls-remote | grep master
to check if there are any refs of the same name. A privileged user can delete refs/for/master
by git push origin :refs/for/master
or git push $remote_url :refs/for/master
.
Upvotes: 18
Reputation: 1324148
By default, a fetch refspec is fetch = +refs/heads/*:refs/remotes/origin/*
So you can also git fetch
(which fetches all the branches), then merge or rebase your branch with origin/<remote branch>
But a more convenient workaround would be to agree on a naming convention for tags: v0.9.0-rc6-patch1
instead of 0.9.0-rc6-patch1
. That way, no more mix-up.
Upvotes: 1
Reputation: 3001
You should use the full name like
git checkout refs/heads/<branchname>
or for tag
git checkout refs/tags/<refname>
For pull
git pull origin refs/heads/<branchname>
To access the relevant documentation type in
git help revisions
Refer the SPECIFYING REVISIONS
section
Upvotes: 4