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

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

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

git remote add heroku [email protected]: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.


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?


Use

git branch --set-upstream-to=origin/remoteBranch localBranch

where origin/remoteBranch is the remote name, and localBranch is the local branch name.