Question

I checked out a friend's pull request using git checkout pr/10 after adding this to my .git/config:

[branch "pr/10"]
    remote = origin
    merge = refs/heads/pr/10

Then I did a bunch of stuff that I can't remember, and now when I type git log the first commit is one from the main repo, not my friend's pull request. I tried git checkout pr/10 again but it doesn't help.

How can I move my HEAD to the tip of the pull request again?

One thing I tried was git checkout 1a234b5, where I copied 1a234b5 from the last commit on the pull request page on GitHub. That seems to move HEAD to the right place, but then when I type git branch it says (detached from 1a234b5).

Was it helpful?

Solution

To simply execute a "I want this branch to point to this commit":

git checkout pr/10  # Checkout the branch
git reset --hard 1a234b5  # Move it 1a234b5.

You might also be able to say:

git checkout pr/10
git reset --hard origin/pr/10

Note that command will reset your working directory and index (due to --hard, feel free to leave that off), so if you have changes, git stash them first.

The git branch -D, git checkout thing works because git, not able to find a branch named pr/10, but seeing that one is in your remote with that name, will create a new branch at the point where your remote branch is, thus recreating it in the right spot.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top