Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push all local branches to origin in git [duplicate]

Tags:

git

Let's say that I have A LOT of local branches in my git not pushed on the remote repository.

How can I push all of them to origin with a single command?

like image 805
napolux Avatar asked May 27 '14 14:05

napolux


3 Answers

Have you tried

git push --all -u 

The git man states

--all

Instead of naming each ref to push, specifies that all refs under refs/heads/ be pushed.

-u, --set-upstream

For every branch that is up to date or successfully pushed, add upstream (tracking) reference,

the -u is useful if you intent to pull from these branches later

like image 179
Fredszaq Avatar answered Nov 19 '22 16:11

Fredszaq


git push <remote_name> '*:*'

The command is intuitive in that it specifies the :. The one on the left of : indicates the name of the local branch and the one on the right specifies the remote branch. In your case, we want to map with the same name and thus the command.

The *:* tells git that you want to push every local branch to remote with the same name on remote. Thus if you have a branch named my_branch you will have a remote branch named <remote_name>/my_branch.

So typically you would do git push origin '*:*' and you would find every local branch with the same name in the remote, which you can confirm by git branch -r which will show you all the remote branches.

like image 41
gravetii Avatar answered Nov 19 '22 16:11

gravetii


You can use a refspec that tells git to push all your branches:

git push origin 'refs/heads/*:refs/heads/*'
like image 4
lrineau Avatar answered Nov 19 '22 17:11

lrineau