Search code examples
gitgit-branchgit-push

Git - How to push single branch to multiple branches


I have three branches dev test master.

Initially i have only dev branch to work with so i used this

git push origin dev

BUt later i will have different branches based on env and will deploy from respective branches. Buntill develeopemet is it possible that test and master always have same head as dev

or in other words

git push origin dev|test|master

so i can push to all branches i single command and later i can merge selective commits. I mean all other branches are same as dev


Solution

  • The refspec is:

    git push remote LocalBranchName:RemoteBranchName
    

    You can list as many of these refspecs as you want in a oneline command:

    git push remote LocalBranchName:FirstRemoteBranchName LocalBranchName:SecondRemoteBranchName LocalBranchName:ThirdRemoteBranchName
    

    So if you want to push 3 copies of the dev branch to the remote under the different names (dev, test, & master), then:

    git push origin dev:dev dev:test dev:master