Last active
March 21, 2026 12:18
-
-
Save Sanushi-Salgado/3dcb3555e08a21462922a4a21a159288 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Useful Git Commands | |
| ✅ View commit messages pushed to remote repo | |
| git log --pretty=format:"%s" | |
| ------------------------------------------------------------------------------------------------------------------------ | |
| ✅ View the last commit on the current branch (including local commits) | |
| git log -1 | |
| ------------------------------------------------------------------------------------------------------------------------ | |
| ✅ Edit the commit message of the last commit pushed | |
| git commit --amend -m "New commit message" | |
| git push --force | |
| ------------------------------------------------------------------------------------------------------------------------ | |
| ✅ Fetch the latest updates of a file from the remote repo | |
| git fetch origin | |
| git checkout origin/<branch-name> -- path/to/file # Replace 'path/to/file' with the file path relative to repo root | |
| ------------------------------------------------------------------------------------------------------------------------ | |
| ✅ Add a new change to the last pushed commit | |
| git add <file1> <file2> # or 'git add .' for all file changes | |
| git commit --amend --no-edit # Omit '--no-edit' if you want to change the message | |
| git push --force origin <branch-name> | |
| ------------------------------------------------------------------------------------------------------------------------ | |
| ✅ Undo the last commit but keep local changes | |
| git reset --soft HEAD~1 | |
| ------------------------------------------------------------------------------------------------------------------------ | |
| ✅ Unstage a file but keep local changes | |
| git reset path/to/file | |
| ------------------------------------------------------------------------------------------------------------------------ | |
| ✅ Fix 'fatal: unable to auto-detect email address (got 'Username@Computer_Name.(none)')' error | |
| git config --global user.name "your_username" | |
| git config --global user.email "your_email" |
Comments are disabled for this gist.