DEV Community

Cover image for 10 Git Commands You’ll Wish You Knew Earlier

10 Git Commands You’ll Wish You Knew Earlier

Balraj Singh on November 28, 2024

Git can feel intimidating when you’re starting out. Most of us stick to the basics: git add, git commit, and git push, and honestly, that works… un...
Collapse
 
prwnr profile image
Rafał

add git switch - to the list. it switches between two last branches, very useful in situations when you need to check something on base branch and there come back to your previous fester or anything

Collapse
 
balrajola profile image
Balraj Singh

I will definitely add this!

Collapse
 
tonymet profile image
Tony Metzidis

my fav: subtree. subtree incorporates other git repos into your repo. it's great for vendoring libraries or refactoring repositories into a new structure. And you can repeatedly pull from upstream. It's a better version of submodule and all commits are copied

Collapse
 
glennturner profile image
Glenn Turner

I get the feeling this will be my new personal favorite. Thanks!

Collapse
 
tonymet profile image
Tony Metzidis
Collapse
 
vikramsinhshinde profile image
vikramsinh shinde

Knowledge upgrades done ✅. Thank you 👍

Collapse
 
balrajola profile image
Balraj Singh

Happy to know that!

Collapse
 
dbolser profile image
Dan Bolser

So close to bingo! Never knew about git --clean thank you!

Personally, I also love git log ..branch.

Collapse
 
balrajola profile image
Balraj Singh

Me too!

Collapse
 
dhanush9952 profile image
Dhanush

git cherry-pick was very helpful

Collapse
 
balrajola profile image
Balraj Singh

Good to know that!

Collapse
 
danishhh profile image
Danish

As always, very useful balraj!

Collapse
 
balrajola profile image
Balraj Singh

Happy to know that!

Collapse
 
gopikrishna19 profile image
Gopikrishna Sathyamurthy

And I use all of them 👍. CLI rules!!

Collapse
 
balrajola profile image
Balraj Singh

Good to know that!

Collapse
 
elinah profile image
ELINAH MMBONE

Thank you 😊

Collapse
 
unixorn profile image
Joe Block

Did you know you can add your own git commands? If you type git foo, git will look for an executable named git-foo.

I have a lot of useful extra commands created that way at git-extra-commands

Collapse
 
redrambles profile image
redrambles

Careful with git clean -f - it will permanently delete untracked files from your working directory and bypasses the trash/recycling bin. Once you run that command, the files are not recoverable.

Collapse
 
fredo- profile image
Alfredo J Velasco

I'd add git checkout -b <branch_name>

It's the easiest fastest way to create a new local branch

Collapse
 
therealbadri profile image
Mahmood Elbadri

helpful