Nov 15, 2017 - To delete the local GIT branch we can try one of the following. Only if you have already pushed and merged it with your remote branches.
$ git statusOn branch masternothing to commit, working directory clean$ git log -oneline2031b83 C4: Master Modified1c0b64c C1: Submitted Code$ git checkout featuresSwitched to branch 'features'$ git log -oneline93d220b C3: Feature 2ad6ddb9 C2: Feature 11c0b64c C1: Submitted Codeec0fb48 C0: Started ProjectNow let’s suppose, you want to bring all the changes from the features branch to our master branch. You will have to start the process from the destination of the merge.
Because we want to merge into the master branch, you need to initiate the process from there. So let’s check out the master branch.
![Branches Branches](/uploads/1/2/5/6/125645263/371436483.png)
![Remove Remove](/uploads/1/2/5/6/125645263/139424849.png)
Within my master branch, I did a git merge some-other-branch locally, but never pushed the changes to origin master. I didn't mean to merge, so I'd like to undo it. When doing a git status after my merge, I was getting this message: # On branch master# Your branch is ahead of 'origin/master' by 4 commits.Based upon some, I tried running git revert HEAD -m 1but now I'm getting this message with git status: # On branch master# Your branch is ahead of 'origin/master' by 5 commits.I don't want my branch to be ahead by any number of commits. How do I get back to that point?
With git reflog check which commit is one prior the merge ( git reflog will be a better option than git log). Then you can reset it using: git reset -hard commitshaThere's also another way: git reset -hard HEAD1It will get you back 1 commit.Be aware that any modified and uncommitted/unstashed files will be reset to their unmodified state. To keep them either stash changes away or see -merge option below.As @Velmont suggested below in his answer, in this direct case using: git reset -hard ORIGHEADmight yield better results, as it should preserve your changes. ORIGHEAD will point to a commit directly before merge has occurred, so you don't have to hunt for it yourself.A further tip is to use the -merge switch instead of -hard since it doesn't reset files unnecessarily: git reset -merge ORIGHEAD-mergeResets the index and updates the files in the working tree that are different between and HEAD, but keeps those which are different between the index and working tree (i.e. Which have changes which have not been added). @JohnBachir: As long as the 'merge' isn't really a fast forward, it will result in a new commit that is at the top of the log, and this commit has two parents (or more than 2 if you do an octopus merge).
If you remove this one merge commit, then all of the older commits that came in from the merge will disappear, too. To be safe, though, after a reset git will tell you where the new head is: 'HEAD is now at 88a04de '. I always look at that to make sure that I ended up where I expected to be. My project uses a standard branch naming scheme to keep things memorable.–Nov 21 '11 at 16:36.