JamesHalsall
JamesHalsall

Reputation: 13495

Git: Forcing pull from specific branch (and preventing override)

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.

Upvotes: 4

Views: 591

Answers (1)

Mark Longair
Mark Longair

Reputation: 467871

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.

Upvotes: 3

Related Questions