7 Git Commands You Probably Don’t Know (But Should)

Think you’re good with Git? Most developers use commands like add, commit, and push every day, but Git has many more helpful commands.

In this post, I’ll show you 7 Git commands that many experienced developers use to work faster, fix problems, recover lost work, and keep their projects organized.

Before we get started, don’t forget to subscribe to my newsletter!
Get the latest tips, tools, and resources to level up your web development skills delivered straight to your inbox. Subscribe here!

Now, let’s jump right into it!

1. git blame

You can use the git blame command to check who last changed each line of a file and when.

It’s helpful for figuring out who made specific changes or understanding a file’s history.

Learn more!

git blame <filename>

2. git cherry-pick

The git cherry-pick command allows you to copy changes from one commit and apply them to another branch.

It’s helpful when you only want to bring over specific changes without merging the entire branch.

Learn more!

git cherry-pick <commit-hash>

👉 Check out my beginner-friendly tutorials over on Learnify, my curated platform to help you learn web development step by step, with examples and simple explanations.

3. git merge — — squash

The git merge — — squash command combines all the changes from one branch into a single commit on another branch.

Instead of creating a merge commit, it squashes all the changes into one, making your commit history cleaner and simpler.

Learn more!

git merge -- squash <branch-to-merge>

4. git rebase -i

The git rebase -i (interactive rebase) command allows you to change your commit history. It lets you reorder, edit, and remove commits.

It gives you more control over your commit log, making it easier to clean up and organize your history.

Learn more!

git rebase -i <base-branch>

5. git reflog

You can use the git reflog command to view a record of all recent changes to your branches and other references.

It can be very useful if you need to recover lost commits or understand recent changes in your project.

Learn more!

git reflog

6. git stash

The git stash command allows you to temporarily save changes that are not yet ready to be committed.

This is handy when you need to switch branches or pull updates but want to save your current work without committing it.

Learn more!

git stash

7. git worktree

The git worktree command allows you to create multiple working directories, each associated with a different branch or commit.

This is useful for working on different tasks simultaneously without having to constantly switch branches.

Learn more!

# Add a new worktree
git worktree add <path> <branch>

# List existing worktrees
git worktree list

# Remove a worktree
git worktree remove <path>

# Remove worktrees that no longer exist
git worktree prune

That’s all for today!

By the way, if you ever need free HTML website templates, I recommend checking out HTMLrev, I use it all the time. And when I’m looking for web design inspiration, Websitevice is one of my go-to resources.

For paid collaboration connect with me at : connect@shefali.dev

If you enjoy my work and want to support what I do:

👉 Become a Patreon supporter
👉 Or buy me a coffee

Every small gesture keeps me going! 💛

Leave a Reply