Create Stash with a Single File/Path
Since git 2.13 you can save a specific file or path to the stash
1
| git stash push -u file.txt
|
Create Stash including untracked files
When running git stash, git will include only the tracked files. If you would like to include untracked files you need to add a flag
1
| git stash --include-untracked
|
Restore the Staged Area
Clean All (tracked and untracked files)
Clean Only Files Ignored by Git
Sometimes if you were just playing on your repo, or for any reason you messed things up, you can just clean changes and untracked files in a single command
Amend last commit
If you just made a commit but you forgot a change you would like to include, you can reset the last commit and make the changes you’d like and do the commit again
Pull with Rebase
If you are in a branch that the history does not match your current one you can pull and rebase in a single command
Push Force safely
Forcing a push is not safe. Thankfully, there is an alternative that makes it safer
1
| git push --force-with-lease
|
Move to the previous branch
If you would like to switch to the previous branch you were, you can just run this command
Rebase branch (main) with your current ranch
To update your branch with a rebase (usually from main) you can run
1
2
| git rebase main
git push --force-with-lease
|
Show one liner log
If you just run git log, you will notice that the output is quite verbose. If you only want to see the hashes, for example, just run
Show Changes on a file
If you would like to check the changes on a specific file/path, just run
Backup repository on a zip file
To backup the repository on a zip file you can run
1
| git archive --format=zip --output=output.zip
|
Show top contributors
To show the top contributors of a specific repo
If you repository slows down and performance is an issue, you can just run the garbage collector
Enable reuse of recorded resolution of conflicts
This is quite useful, as you command git to record how you fied previous conflicts and make it learn from it for the future
Show history of a specific file
To check all the changes made on a specific file over time, run
1
| git log --follow file.txt
|
Show last commit changes
Sometimes you just want to check what were the latest changes made on the last commit.