Three useful Git commands you might not know
Hey there! I’m Srebalaji. You are receiving this email because you have subscribed to level up your game in Git.
Git stash only particular files
git stash push <file_name>
The above command will stash only the particular files you mention. Other files are untouched.
You can also mention multiple file paths
List all branches ordered by most recent commits
git branch --sort=committerdate
The above command will list branches in order of the most recent commits. So you can see the branches you have been using most recently.
It is a very helpful command that comes in handy when working with multiple branches.
Cleaning up the git repo
git remote prune origin && git repack && git prune-packed && git reflog expire --expire=1.month.ago && git gc --aggressive
git remote prune origin
- Deletes all the local references of the remote branch
git repack
-
Packs are internal parts of Git. This command helps you to create a new pack and so reducing disk sizes
git prune-packed
- Deletes extra objects present in the Git packs
git reflog expire
- The above command will remove all refs that are older than one month
git gc
- This command runs Git garbage collection that helps deletes extra data
You can have it as an alias and run it weekly once to have a clean repo.
That’s it for today.
See you next week :)