Git checkout a commit and attach to existing branch
commit, git, head
Solution
If you want to merge up to a specific commit, fetch all remote changes and specify this commit's id:
git fetch origin
git merge <sha1 of commit you want to merge>
You can specify the `--ff-only` option and have Git fail when it cannot fast-forward (and would create a new merge commit).
If you only want to put a single commit on top of your current branch's tip, use cherry-pick (but this is usually not recommended):
git cherry-pick <sha1 of commit you want to merge>
Problem
I have a local repo and I want to fast-forward it to a specific commit (which may not be the HEAD of the remote repo). So I do: ``` git fetch master git checkout sha ``` This however puts me in a detached HEAD state, which I don't want. Is there an equivalent to `git checkout -b branch_name sha`, which works when branch_name already exist? In short, I have to update the HEAD of my local repo to a remote commit. I already tried `git pull origin sha` with no success. I cannot use `git pull origin master` because that will fast-forward to the HEAD of the remote, while I want to fast-forward to a specific commit.