1. How to remove last commit
1 |
git reset --hard HEAD~1 |
2. How to edit an incorrect commit message
1 |
git commit --amend |
or
1 |
git commit --amend -m "New commit message" |
3. How to “Undo” a wrong git add
1 |
git reset filename |
4. How to delete a git branch locally and remotely
1 |
git branch -d local_branch |
1 |
git push origin --delete remote_branch |
5. How to rename a branch
1 |
git branch -m old_name new_name |
or if you are on the branch you want to rename
1 |
git branch -m new_name |
6. How to remove local (untracked) files from the current git branch
show the file before to remove then with
1 |
git clean -f -n |
physically remove files with
1 |
git clean -f |
physically remove directories with
1 |
git clean -fd |
7. How to temporary switch to an old commit
1 |
git checkout commit_id |
8. Resolve merge conflict
1 |
git mergetool |
9. Force a git pull to overwrite local changes
1 |
git reset --hard origin/branch_name |
10. How to show a list of remote and local available branches
1 |
git branch -a |