Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does "git push" push all commits from other branches?

Tags:

If I have many unpushed commits spread among many branches in my local repo, what happens if I type git push? Will all of those commits be pushed or only those which belong to the current branch?

like image 675
Liglo App Avatar asked Sep 30 '13 07:09

Liglo App


People also ask

Does git push affect other branches?

By default, git push only updates the corresponding branch on the remote. So, if you are checked out to the main branch when you execute git push , then only the main branch will be updated. It's always a good idea to use git status to see what branch you are on before pushing to the remote.

What does -- all do in git push?

--all is the flag that signals that you want to push all branches to the remote repository. REMOTE-NAME is the name of the remote repository you want to push to.


2 Answers

No, git push only pushes commits from current local branch to remote branch that you specified in command.

You can tell git to push all branches by setting the --all argument

See the command description

like image 103
Shimon Rachlenko Avatar answered Oct 22 '22 14:10

Shimon Rachlenko


It also depends on your push policies (git config push.default).

As I explain in "git - push current vs. push upstream (tracking)", only the "matching" policy pushes more than the current branch.

push all branches having the same name on both ends.
This makes the repository you are pushing to remember the set of branches that will be pushed out (e.g. if you always push maint and master there and no other branches, the repository you push to will have these two branches, and your local maint and master will be pushed there).

With that policy, only a simple git push is enough to push all (matching) branches.
Without that policy, a git push --all is necessary to force all branches to be pushed.

like image 22
VonC Avatar answered Oct 22 '22 13:10

VonC