Search code examples
gitpushgit-push

Git: How to push local branch to renamed remote branch?


I have a remote repository and a local repo. I did a git fetch --all and see the branch I want in the local repo, I think create a local tracking branch:

git checkout -t -b bug1000 origin/user/bug/1000

My problem is the pull's are correct, but push's are not setup:

>$ git remote show origin
* remote origin
  Fetch URL: XXX
  Push  URL: XXX
  HEAD branch: master
  Remote branches:
    maint                                      tracked
    master                                     tracked
    user/bug/1000                              tracked
    user/bug/1001                              tracked
    user/bug/1002                              tracked
  Local branches configured for 'git pull':
    bug1000     merges with remote user/bug/1000
    maint       merges with remote maint
    master      merges with remote master
  Local refs configured for 'git push':
    maint       pushes to maint       (local out of date)
    master      pushes to master      (local out of date)

My .git/config looks correct:

[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = XXX
[branch "master"]
        remote = origin
        merge = refs/heads/master
[branch "maint"]
        remote = origin
        merge = refs/heads/maint
[branch "bug1000"]
        remote = origin
        merge = refs/heads/user/bug/1000

I have already tried git push -u origin bug1000:user/bug/1000 but it doesn't change anything.

This is using git 1.7.10.2 (latest stable as of writing).


Solution

  • You can add a push entry for that remote, but if you have a lot of these, that might get cumbersome:

    [remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = XXX
        push = refs/heads/bug1000:refs/heads/user/bug/1000
    

    If you added another virtual "directory" and used bug/1000 locally instead of bug1000, then the push config could be push = refs/heads/bug/*:refs/heads/user/bug/*, which might be cleaner in the long run.