Git: force pulling from a specific branch (and preventing overriding)

I know that there are questions floating around regarding git pull from a specific branch when you do not specify an explicit branch name, however I am wondering if it is possible to force if the user indicates another branch.

Example.

If I needed to log into a live server and pull out the latest changes, I only want changes from the branch in real time . Therefore, if I were to do the following in a shell:

git pull origin master

I would like to git either

  • Throw error message
  • Ignore it and just pull it out of the active branch on the remote

Is it possible? I hope to avoid situations like this , and because this is the main business system, it is not good when everything goes wrong.

+4
source share
1 answer

If this is your production server, it seems like a bad idea to let someone run arbitrary git commands in this repository. Any merging (e.g. with git pull ) can create conflicts that leave your live server with a broken setting. I think that people usually deal with this problem by allowing developers to deploy to a production server by clicking on an empty repository with a post-receive or update hook that checks:

  • If refs/heads/master updated
  • If so, check it on the new directory using

     GIT_WORK_TREE=/deployment/directory git checkout -f 

Of course, this does not stop people from combining not only what happens locally, and then clicking on an intermediate server or a live server, but you are unlikely to be able to do this, I think - people just need to check theirs (locally or on an intermediate server) before than press.

+3
source

All Articles