I want to rename a branch
$ git branch -m <currentname> <newname>
Source: dmo.ca blog
I’ve forgotten which branch my branch was created from
$ git log -g <branchname>
or
$ git reflog show <branchname>
and look for the first entry (assumes branch was created recently).
Source: Stack Overflow
=====================================================================
Careful! The following hints assume you haven’t pushed your changes.
=====================================================================
I’ve just committed my changes to the wrong branch
1. Do $ git reset --soft HEAD^
– this will undo the commit but leave the changes staged.
2. Checkout the branch you actually wanted to commit to.
3. Commit your changes.
Source: Stack Overflow
I’ve just done a hard reset and need to undo it
1. Do $ git reflog
and look up the sha1 of the commit you want to go back to
2. Do $ git reset --hard <sha1 to return to>
Source: Stack Overflow
I missed out a file a couple of commits ago
1. Commit the files you want to add to the commit
2. Do $ git rebase -i HEAD~<number of commits to go back>
3. Your text editor will bring up the list of commits. Re-arrange the rows into the desired order (oldest first) and change ‘pick’ to ‘squash’ for the commit you want to merge.
4. After saving that file, the text editor will ask you to specify a message for the merged commit.
Source: git-scm