Using git, how do a merge a tracked branch back into the remote origin/HEAD?



I got myself into a little bit of a local repo mess. Long story short, I had a copy of a remote repo; I created a branch called ‘my_branch’ in my local repo; I committed work a few times. I then just pushed the branch to the remote repo. Here’s my local repo diagram…(since I’ve pushed my_branch to the remote, this is what remote looks like too).

--C0--------------C4--  (local master) 
       --C1-C2-C3--     (local my_branch)

I then decided to try to rebase, but I think I totally messed up. I also tried to do git reset --hard and I think I corrupted my local repo some more. So I decided to start from a clean place. I grabbed my_branch from the remote repo following this.

I then checked out origin/my_branch from remote. (I now see that I have a “detached HEAD” in my GUI tool GitX.) Now…how do I merge this branch with origin/HEAD aka origin/master on remote?


Make a branch right where you are to get that work tracked

git checkout -b new-branch HEAD

Now you can check out other branches and merge or rebase them.

To get a local branch for a remote one that you are not tracking yet:

git checkout -t origin/some-branch

Now just push up the branches. Most likely you will require a force push

git push -f origin some-branch

Answered By – Adam Dymitruk

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More