Search code examples
gitgit-pushgit-remote

Git heads messed up?


Under branch dev, when I run

git status

I get

On branch dev
Your branch is up-to-date with 'hub/dev'.

nothing to commit, working directory clean

When I run

git remote show hub

I get

* remote hub   
  Fetch URL: ssh://[email protected]/home/user/private/repos/user_hub.git
  Push  URL: ssh://[email protected]/home/user/private/repos/user_hub.git   

  HEAD branch: master   
  Remote branches:
            dev        tracked
            master     tracked
            userModule tracked
  Local branches configured for 'git pull':
            dev    merges with remote dev
            master merges with remote master
  Local refs configured for 'git push':
            dev        pushes to dev        (up to date)
            master     pushes to master     (up to date)
            userModule pushes to userModule (up to date)

I didn't expect to get HEAD branch: master. What's wrong?

Problem / Question

Under dev, when I run git push, it pushes to the hub/master, whereas it should be pushed to hub/dev. How can I fix this, so that, when we are on branch dev, it pushes to the hub/dev instead?

Update

According to some comments, the configuration above seems correct.

See my post-update hook below; could the problem be caused by it?

#!/bin/sh

echo
echo "**** Pulling changes... [Hub's post-update hook]"
echo

case " $1 " in
*'refs/heads/dev'*)
cd /home/user/www/dev/ || exit
        unset GIT_DIR
        git pull hub dev
        echo
        echo "Dev was pulled"
        echo
        ;;
esac

case " $1 " in
*'refs/heads/master'*)
        cd /home/user/www/www/ || exit
        unset GIT_DIR
        git fetch hub && git reset --hard hub/master
        echo
        echo "Master was reset to reflect bare changes. PRAY THE LORD!"
        echo
        ;;
esac

exec git-update-server-info

Here's the git config:

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
        precomposeunicode = true
[remote "hub"]
        url = ssh://[email protected]/home/user/private/repos/user_hub.git
        fetch = +refs/heads/*:refs/remotes/hub/*
[branch "master"]
        remote = hub
        merge = refs/heads/master
[branch "dev"]
        remote = hub
        merge = refs/heads/dev
[merge]
        renameLimit = 999999

Update 2: The issue seems to be solved, but as far as I can tell, I did nothing to "fix" it. :s Still, if someone cares to clarify if something is wrong, or why this could be a problem, please let me know. Thank you very much.


Solution

  • What version of git are you using?
    Prior to git v2.0 git push will push all your branches in no origin/branch name supplied !!!

    Read the first paragraph of the release notes: https://git.kernel.org/cgit/git/git.git/tree/Documentation/RelNotes/2.0.0.txt

    When "git push [$there]" does not say what to push, we have used the traditional "matching" semantics so far (all your branches were sent to the remote as long as there already are branches of the same name over there). In Git 2.0, the default is now the "simple" semantics, which pushes:

    • only the current branch to the branch with the same name, and only when the current branch is set to integrate with that remote branch, if you are pushing to the same remote as you fetch from; or

    • only the current branch to the branch with the same name, if you are pushing to a remote that is not where you usually fetch from.

    You can use the configuration variable "push.default" to change this. If you are an old-timer who wants to keep using the "matching" semantics, you can set the variable to "matching", for example. Read the documentation for other possibilities.

    As you described in your Question - your dev status is clean but when you push it pushes to master. sounds like you had some un-pushed commits in master so git push simply pushed master as well.