Web dev

The top 10 most useful git commands

1. How to remove last commit

git reset --hard HEAD~1

2. How to edit an incorrect commit message

git commit --amend

or

git commit --amend -m "New commit message"

3. How to “Undo” a wrong git add

git reset filename

4. How to delete a git branch locally and remotely

git branch -d local_branch
git push origin --delete remote_branch

5. How to rename a branch

git branch -m old_name new_name

or if you are on the branch you want to rename

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

git clean -f -n

physically remove files with

git clean -f

physically remove directories with

git clean -fd

7. How to temporary switch to an old commit

git checkout commit_id

8. Resolve merge conflict

git mergetool

9. Force a git pull to overwrite local changes

git reset --hard origin/branch_name

10. How to show a list of remote and local available branches

git branch -a

 

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.