Protected branch and commits

Im using the GitHub extension for Visual Studio.

I have a project with a protected branch (master).

A friend of my have cloned the project through visual studio, and forgot to make a new branch before making a change and a commit.

He cannot push this commit to GitHub. Which is good.

But how can he remove the change/commit he made locally, so it will disapear from the commits to sync?

Maybe you need the stash command: git-stashing

Nope, stashing is used to save current work temporarily (on a stash, hence the name).


The command below will PERMANTENTLY delete the commit! Use with caution - never execute commands random people on the internet suggest without having a backup and knowing what they do!


git reset HEAD~1

This will undo the last commit and leave your current changes as they are.

You are right… But instead of stashing he can create a new branch from the local master and push to origin this new branch, then reset the local master to origin/master.  Whit this method no modify were lost and they can review from a PR in github.

In line there are the commands you need to run:

git checkout -B new_branch

this command will create a new branch keeping all the changes made.

Then push this new_branch to origin:

git push origin new_branch

Return to master:

git checkout master

and reset with the origin master with:

git reset --hard HEAD^

This done the trick.


1 Like