Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git pull on non-working branch without switching

We have a development branch which is our master and a separate maintenance branch. I frequently have to cherry-pick commits from the master to the maintenance or vice-versa when I fix bugs. Normally I accomplish this by performing the following procedure...

  1. Commit on the master branch
  2. Push commit to remote
  3. Switch/Checkout to maintenance branch
  4. Cherry-pick the commit from step 1
  5. Build and make sure everything is still working as intended
  6. Push maintenance commit to remote

The problem that I have is because the branches have become significantly divergent I have to rebuild the entire project each time I switch which takes up to 10 minutes. This is expected, but I'd like to not have to do this since I'm frequently switching between branches. So to avoid this I created a second working directory so that I have a directory for each branch. The problem with this is that I can't cherry-pick the original master commit into the maintenance directory until I've pulled that commit into the master branch of the maintenance directory from the remote. When I do this of course, I have to completely rebuild.

Is there a way to pull the commits into the master branch of my maintenance directory without switching? Or, is there a better way of doing this entirely? We recently switched to Git from CVS, so I'm not that familiar with it.

like image 497
John Brooks Avatar asked Dec 22 '15 21:12

John Brooks


1 Answers

You can download the new commits into the other repository simply by running fetch (in the other repository):

git fetch origin

However, fetch will only update the remote tracking branches, not the local branches, so master will not move, but origin/master will. So you can cherry-pick the newest commit with:

git cherry-pick origin/master

(To my knowledge, there is no elegant way to create a new commit atop another branch than the one that is currently checked out, so I think you need to stick to the two repositories if you don't want to switch branches. Sounds like you'll need that anyway in order to test the changes you make on the other branch?)

like image 189
Aasmund Eldhuset Avatar answered Oct 17 '22 11:10

Aasmund Eldhuset