Why does `git merge origin` work some of the times?

Arnold Daniels

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.

Whymarrh

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.

edited at
0

Comments

0 comments
Login to comment

Related

why "git fetch origin bugfix" does not work?

Why does "git push origin @" not work?

Why does git merge origin/master not generate a commit message?

Why local git repo does not see the merge executed on origin?

Why does "git push" work after doing "git push origin --delete BRANCHNAME"?

`git push origin master` does not work

iOS Swift Animation does not work some times

How does 'git merge' work in details?

Does git merge work against a remote branch?

Why does git paginate not work after adding merge.tool and diff.tool?

Why merge with update does not work as intended?

Why this Merge Sort does not work properly?

Why does this merge sort algorithm not work properly?

Why does this merge sort implementation not work?

Why does git rebase ignore merge commits?

Why does git merge a branch into itself?

Why does this GIT merge not result in conflicts?

Why "git push origin master" doesn't work?

git push -u origin --all does not work anymore

Why regex doesn't work some times in javascript?

When running git status the message "your branch is up-to-date with 'origin/branch' only appears some times

Why \b does not work correctly for some languages?

Why constructor does not work in some cases?

Why does if ( 'a'<= /*some char*/ <= 'z') not work?

why some nested aggregate case does not work?

Why does git pull origin develop --rebase cause conflict when git pull origin develop doesn't?

Why does Git tell me "error: No such remote 'origin' " when i try git remote remove origin?

Is git merge origin master same as git merge origin/master?

Git merge origin with a branch with slash

TOP Ranking

HotTag

Archive