Can I map local branches to remote branches with different prefixes in git?

前端 未结 4 857
我寻月下人不归
我寻月下人不归 2021-02-13 19:01

We\'re working with a semi-centralized git repository here where I work. Each developer has their own subtree in the central git repository, so it looks something like this:

相关标签:
4条回答
  • 2021-02-13 19:15

    Use

    git branch --set-upstream-to=origin/remoteBranch localBranch
    
    0 讨论(0)
  • 2021-02-13 19:16

    In your [remote "origin"] section, add one line per mapping. Including master to master.

    push = refs/heads/master:master
    push = refs/heads/topic/feature:michael/feature
    

    I'm not sure how to do it with the git-config command.

    Be aware that from now on, all branches are pushed at the same when you do a straight git push (with no params).

    Would you care to explain why you don't keep the same branch names locally and remotely?

    0 讨论(0)
  • 2021-02-13 19:20

    If you can, I suggest you use the same branch names locally & remotely. Then git push will push all of your local branches to corresponding branches in the central repository.

    To use different prefixes in local and remote repos, you need to add a mapping to your config file each time you create a new feature branch. The command to set up the mapping for topic/BRANCH_NAME is

     git config remote.origin.push refs/heads/topic/BRANCH_NAME:michael/BRANCH_NAME
    
    0 讨论(0)
  • 2021-02-13 19:20

    You can map your branch to different tracking branch on the remote with something like this:

    git remote add heroku git@heroku.com:YOURAPPNAME.git
    git checkout -b heroku -t heroku/master
    

    Your config ends up similar to what @Paul suggests (a tad "simpler" actually).

    See this gist (with tweaks by me) for usage steps that work well for me https://gist.github.com/2002048.

    0 讨论(0)
提交回复
热议问题