Instead of doing git merge origin/branch
I like to do git merge origin
. Omitting the branch name makes automating and creating aliases a bit simpler.
However git merge origin
only works for some repositories:
$ git branch --set-upstream-to=origin/master
$ git pull origin
Already up-to-date.
$ git merge origin
Already up-to-date.
For other repos there is an error:
$ git branch --set-upstream-to=origin/master
$ git pull origin
Already up-to-date.
$ git merge origin
merge: origin - not something we can merge
Note that the statement git pull origin
works for both repositories.
Both repositories or on the same system (so running the same version of git). I've examined the .git/config
and it looks similar for both repos.
It works for
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = [email protected]/obfuscated-repo-1.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
It does not work for
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = [email protected]:legalthings/iam.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
Why does this work in some cases and not in others?
For the repo where it's not working, git rev-parse origin
gives an error:
git rev-parse origin
origin
fatal: ambiguous argument 'origin': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]
For the other repository I'm getting a commit hash.
When you run git merge origin
you are implicitly saying git merge origin/HEAD
, where origin/HEAD
is the default branch on your remote. The HEAD
reference will get set when you run git clone $repo
.
If your remote does not have a HEAD
reference, you created the repository locally and pushed it to the remote, in which case Git will not know what the default branch is (and git fetch origin
will not set it). You can manually set the HEAD
ref for the remote via:[1]
git remote set-head origin $branch
where $branch
is the name of the branch that you want to set as the default branch for that remote.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments