DEV Community

Cover image for 3 Git features that changed how I work (and you probably aren't using them)
Ashadul Mridha
Ashadul Mridha

Posted on

3 Git features that changed how I work (and you probably aren't using them)

So I've been using Git for years, but honestly? I was just doing the basic add, commit, push routine. Then I discovered these three features and they genuinely made my workflow so much smoother.

1. Git Submodules - because copy-pasting code is exhausting

Here's the thing - I had this auth library that I needed in like 5 different microservices. First, I was literally copy-pasting it everywhere. Nightmare to maintain. One bug fix meant updating 5 repos manually.

Then I learned about submodules. Basically, you can include one Git repo inside another. Now I have a shared repo with common utilities, and all my projects reference it as a submodule. When I update the auth logic? Just run git submodule update in each project and boom, everyone's on the latest version.

Yeah, there's a learning curve, but it beats manually syncing code across projects.

2. Cherry-pick - for when you need THAT specific commit

This one's a lifesaver. You know when you fix a bug in one branch but need that same fix in another branch? Without merging the entire thing?

Last week I was working on a big feature branch. Production went down because of some API timeout issue. I quickly switched to main, fixed it, committed. But now my feature branch has the same bug. Instead of merging everything or fixing it again, I just cherry-picked that one commit:

git cherry-pick <commit-hash>
Enter fullscreen mode Exit fullscreen mode

Saves so much time and keeps the history clean.

3. Git Stash - your work-in-progress safety net

Okay this is probably the one I use most often. Picture this: you're halfway through implementing something, code's messy, nothing's working yet. Then your team lead pings you - "urgent bug in production, need you to check it out NOW."

You can't commit half-baked code. But you also can't lose your work. That's where stash comes in:

git stash              # saves your current mess
git checkout main      # switch branches safely
# fix the urgent stuff
git checkout feature   # back to your branch
git stash pop          # and your work is right there
Enter fullscreen mode Exit fullscreen mode

I probably stash stuff 3-4 times a day. It's become muscle memory at this point.

Quick tip: If you're learning these, start with stash. It's the easiest and you'll use it constantly. Cherry-pick is next. Submodules are powerful but you might not need them unless you're dealing with shared code across multiple projects.

Top comments (0)