DEV Community

Cover image for Git Tips I Wish I Knew Earlier (For Everyday Productivity)
Vrushik Visavadiya
Vrushik Visavadiya

Posted on

Git Tips I Wish I Knew Earlier (For Everyday Productivity)

We use Git every day — but most of us stick to just add, commit, and push.

Here are small, daily-use improvements that can make your Git workflow smoother starting today.


1️⃣ Undo the Last Commit (Without Losing Changes)

Made a typo in your commit message or forgot a file?

Instead of making a new commit:

git commit --amend
Enter fullscreen mode Exit fullscreen mode

💡 Pro Tip: Add --no-edit if you just want to keep the same message.


2️⃣ See What You’re About to Commit

Before committing, check your staged changes:

git diff --staged
Enter fullscreen mode Exit fullscreen mode

No more “Oops, I didn’t mean to commit that file!” moments.


3️⃣ Quickly Switch Back to the Last Branch

git checkout -
Enter fullscreen mode Exit fullscreen mode

or (modern way):

git switch -
Enter fullscreen mode Exit fullscreen mode

Great for jumping between two branches while fixing something quickly.


4️⃣ Save Work-in-Progress Without Committing

Got interrupted? Use stash:

git stash
# ...do something else...
git stash pop
Enter fullscreen mode Exit fullscreen mode

You’ll get your work back exactly as it was.


5️⃣ Pull with Rebase for a Cleaner History

Instead of mixing merge commits in your history:

git pull --rebase
Enter fullscreen mode Exit fullscreen mode

This keeps your commits in a straight line — much easier to read.


6️⃣ Avoid Typing Long Commands with Aliases

git config --global alias.s "status -sb"
git config --global alias.lg "log --oneline --graph --decorate"
Enter fullscreen mode Exit fullscreen mode

Now:

git s
git lg
Enter fullscreen mode Exit fullscreen mode

Your fingers will thank you. 🙌


7️⃣ View Who Changed a Line in a File

git blame filename.js
Enter fullscreen mode Exit fullscreen mode

Perfect for finding the commit (and person 😏) behind that mysterious code.


8️⃣ Ignore Files You Forgot to Ignore

git rm --cached file.log
echo "file.log" >> .gitignore
Enter fullscreen mode Exit fullscreen mode

Now Git will stop tracking it — but it stays in your local folder.


📌 Final Thought

You don’t have to memorize 200+ Git commands —

just a few well-chosen habits can save you hours every week.


💬 Which of these do you use daily?

Drop your favorite Git tip in the comments so we can all improve together!

Top comments (0)