Set up git to pull and push all branches
I'd like to push and pull all the branches by default, including the newly created ones.
Is there a setting that I can define for it?
Otherwise, when I add a new branch, locally and I want to pull it from the server, what is the simplest way to do it?
I created a new branch with the same name and tried to pull but it doesn't work. Asks me for all the remote config of the branch. How do I set it.
The simplest way is to do:
git push --all origin
This will push tags and branches.
With modern git you always fetch all branches (as remote-tracking branches into refs/remotes/origin/*
namespace, visible with git branch -r
or git remote show origin
).
By default (see documentation of push.default
config variable) you push matching branches, which means that first you have to do git push origin branch
for git to push it always on git push
.
If you want to always push all branches, you can set up push refspec. Assuming that the remote is named origin
you can either use git config:
$ git config --add remote.origin.push '+refs/heads/*:refs/heads/*'
$ git config --add remote.origin.push '+refs/tags/*:refs/tags/*'
or directly edit .git/config
file to have something like the following:
[remote "origin"] url = [email protected]:/srv/git/repo.git fetch = +refs/heads/*:refs/remotes/origin/* fetch = +refs/tags/*:refs/tags/* push = +refs/heads/*:refs/heads/* push = +refs/tags/*:refs/tags/*
Including the + in the push spec is probably a bad idea, as it means that git will happily do a non-fast-forward push even without -f, and if the remote server is set up to accept those, you can lose history.
Try just this:
$ git config --add remote.origin.push 'refs/heads/*:refs/heads/*'
$ git config --add remote.origin.push 'refs/tags/*:refs/tags/*'
$ git config --add remote.origin.fetch 'refs/heads/*:refs/remotes/origin/*'
$ git config --add remote.origin.fetch 'refs/tags/*:refs/tags/*'
I had used below commands to migrate all branches to the new repository.
~$ git clone --mirror <url_of_old_repo>
~$ cd <name_of_old_repo>
~$ git remote add new-origin <url_of_new_repo>
~$ git push new-origin master
~$ git push new-origin --mirror
NOTE: I had to use second last (i.e. push master first) command while cloning a repo from Atlassian Stash to AWS CodeCommit (blank repo). I am not sure the reason, but after pushing (git push new-origin --mirror
) default branch was referring to some other branch than master
.