Question

I have a website that I deploy with git. It is stored (for source control purposes, not deployment) on the 'origin' remote on branch 'production' (also my local branch). So I can maintain my source code there with a simple:

$ git push

(i.e. I have the default push set up to push 'production' to 'origin/production').

I have a test server and a live server, configured as git remotes, and I currently deploy with:

$ git push test production:master

$ git push live production:master

I.e. those remotes are using their master branch - they have no 'production' branch, or indeed any concept or knowledge of this branch name.

I'm wondering if there's a way to set up my .git/config such that I can simply do this:

$ git push test

and

$ git push live

and it will push my local production branch to the remotes' master branches, as before.

This may sound like I'm being lazy (and I probably am), but I'm also hoping that the answer to this will help me understand a bit more about how remotes and branches are configured.

Was it helpful?

Solution

You can configure it with the push setting in .git/config:

 [remote "test"]
      push = production:master

 [remote "live"]
      push = production:master

The push setting is the <refspec> used by git push when none is given, e.g. git push test.

(For the push setting above to take effect you have to have the 'production' branch currently checked out)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top