RSS Amplifier

GingerDev · Oct 14, 2024

Top 5 GIT commands for a productive workplace

0
Sign in to vote or save

Abhinay Kumar · GingerDev

Internet is swamped with in depth GIT tutorials and every time I look at them, I wonder how those massive list of commands are ever going to be helpful for anyone but Linus Torvalds (since he built the tool) and bunch of other smart programmers. Luckily I side stepped all that complexity at work and survived with just the handful of them.

So here it goes my top 5 most used GIT commands for a peaceful work.

# Delete all branches except develop and main
1. git branch | grep -v "develop" | grep -v "main"| xargs git branch -D

I hate the clutter of git branches and that is why command to deleting all branches except the ones that I want to keep is my all time favourite.

2. git merge branch_name

As the ultimate goal is to bring the changes from one branch (feature branch) into another (main branch) and if you do not care about clean commit history (which is the majority of the cases) then don’t stress about not using git rebase and somehow missing the 10x engineer train.

3. git config --global alias.st status

aliases are the productivity boosters that allows you to remain in your flow state. I use them for practically all git related actions.

4. git stash

Sometimes, life's like working on a feature branch—messy, incomplete, but necessary for progress. Stash the chaos, switch focus, and come back stronger when you're ready to merge. Learnt this command pretty late in my career and I must say this is one of smartest trick in the GIT world.

5. git restore .

I have made accidental changes many times in a branch that I wasn’t suppose to and before finding out about git restore, I use to manually revert changes in each file, then I started stashing them which forced me to navigate around git stash and related commands hence here is the bonus GIT command that I had to pick up as I did not know about git restore

6. git stash apply stash@{i}

GIT maintains the order of stashed code and you can retrieve them anytime you like. club it with git stash list and you wouldn’t have to stress about 1 less thing.

Happy gitting!!

Read the original on gingerdev.substack.com

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.