4

I know there are questions floating around regarding git pull from a specific branch when you provide no explicit branch name, however I am wondering if it's possible to force a pull branch even if the user does specify a different branch.

Example.

If I was to log into a live server and pull the latest changes, I only want changes from the branch live. So if I was to execute the following in the shell:

git pull origin master

I would want git to either

  1. Throw an error
  2. Ignore it and just pull from the live branch on the origin remote

Is this possible? I'm hoping to avoid any situations like this one and because it's a core business system it's not good when things go awry.

Community
  • 1
  • 1
JamesHalsall
  • 13,224
  • 4
  • 41
  • 66
  • You probably shouldn't use git as a deployment tool. Anything you do (for example, alias `git pull` to `git pull origin live`) could probably be easily circumvented, accidentally or otherwise. – Ben James May 23 '11 at 16:04

1 Answers1

3

If this is your production server, it seems like a bad idea to allow anyone to run arbitrary git commands in that repository. Any merge (e.g. with git pull) might create conflicts that leaves your live server with a broken setup. I think people normally deal with this problem by only allowing developers to deploy to the production server by pushing to a bare repository that has a post-receive or update hook that checks:

  1. If refs/heads/master is being updated
  2. If so, checks it out to a new directory with:

    GIT_WORK_TREE=/deployment/directory git checkout -f
    

Of course, this doesn't stop people from merging the wrong thing locally and then pushing that to a staging server or the live server, but there's not much you can do about that, I think - people just have to test their commit properly (either locally or on the staging server) before pushing.

Mark Longair
  • 446,582
  • 72
  • 411
  • 327
  • Thanks for the reply, I can now see that what I'm doing is not an ideal solution. Do you know of any tutorials/articles on this type of deployment practice? – JamesHalsall May 24 '11 at 09:18
  • @Jaitsu: not really beyond what you'd get from Googling "git" and "deployment", I'm afraid. I've been meaning to write a blog post about that issue, though - I hope I'll have time for that soon. – Mark Longair May 25 '11 at 13:45