Git - My Cheat List


My Git Cheat List

How to rebase a forked repository

On the cloned repository

$ git checkout master
$ git remote add upstream
$ git fetch upstream
$ git rebase upstream/master
$ git checkout my-branch
$ git rebase master

How to add a default editor to git

$ git config --global core.editor vim

How to amend to some old commit?

$ git log

Get the hash of the commit you wish to edit

$ git rebase -i 123456

It will open your editor with the commit options written as pick

Change it to edit

Your branch name is now changed to the commit’s hash. Edit your files then:

$ git add yourfile
$ git commit --amend

Once you have finished all changes:

$ git rebase --continue 

Everything is back to normal. Since you made a rebase, you need a “forced” push:

$ git push -f