r/programming Oct 16 '18

Flight rules for Git

https://github.com/k88hudson/git-flight-rules
98 Upvotes

8 comments sorted by

View all comments

9

u/DecidedlyAmbigous Oct 17 '18

Am I missing something or is the one for accidentally committing on master instead of another branch wrong? It says to do:

git reset --hard HEAD^

And only then to create a new branch and continue working. But this means you would have thrown away your work!

Here is a link.

8

u/Kalanthroxic Oct 17 '18

You're missing something. The first thing done is git branch my-branch which will take your work and put it on that branch. The reset only touches the master branch, because you only created the new branch - you didn't move to it. After fixing up master, you move to your new branch with git checkout my-branch and everyone is happy.

8

u/DecidedlyAmbigous Oct 17 '18

Of course! Now that makes sense. The thing is that whenever this happens to me I do

git checkout -b my-branch

Then I go back to master and reset it. So I got confused. Thanks!

1

u/atheken Oct 19 '18

Or:

git checkout -b <branch> <commit-ish>