Pull for another Git branch without switching

git

we recently switched from SVN to Git and at the same time put our live systems into version control (instead of local checkout and file copy to live).

On the project i'm assigned to we all access the same repository and to get changes into live we just git pull there. This causes problems because our webdesigners push changes into the VCS that should not be live yet but should be on the web-testing environment.

When one of the developers now pulls into live he gets all (possibly unfinished) changes.

I thought of switching live to an extra branch and just merge what changed but due to my lack of git knowledge i have no idea how.

My idea is:

  • Create a new Branch in live (git branch live).
  • Every time something has to go live
    • Pull changes in master (like: git
      checkout master; git pull; git
      checkout live
      )
    • git merge master

The problem is that switching to master or pulling everything directly into the live system would cause problems so i'd prefer to avoid this.

Is there any way to do this or is there any better way to manage the Live system (except for training the webbies to not push unfinished stuff).

Best Answer

I was able to pull changes from origin/master into master while working in another branch by using this command:

git fetch origin master:master

For a deeper dive into what's going on, check out the excellent answer to this Stack Overflow question. The main take-away for me was that this command only works for a fast-forward merge.