I wanted to share a neat tip that I discovered this morning.
I am currently working with two branches, one that a couple of developers maintain, and one that I maintain, which contains some build artifacts. I wanted to maintain some of the files in my branch current to the developers branch, but I did not want to merge everything.
This is where the checkout feature comes handy.
Say that there is a image1.png file in the dev branch that I need to merge in my build branch.
I simply run the following commands
$ git checkout build $ git checkout dev image1.png $ git add .
This adds the image that is in the dev branch to my build branch.
Notice that I can also use a wildcard with that feature:
$ git checkout dev images/*
Pretty cool eh :)
Be careful not to confuse this with the Git cherry-pick command. The checkout process that you describe above restores a file from a specified branch into your current branch. This is slightly different than cherry-picking a commit.
You can use git cherry-pick <commit> to apply a specific commit on to your branch. This can be useful when manually grabbing whole commits from a branch without integrate other changes.