DEV Community

Cover image for Git Commands ( to ease your development 🤗 )

Git Commands ( to ease your development 🤗 )

Shivam on June 23, 2022

Git is a prevalent version control system ( VCS ) used by most programmers. In this blog, I am going to share some tips with basic commands to make...
Collapse
 
dakdad profile image
Asanka

Good summary for useful basic git commands.

git stash pop only retrieves the first item (stash@{0}) from the stash list and then the index is refreshed (stash@{1} if it was there becomes the stash@{0} to take the place of the one popped out)

Collapse
 
shivam164 profile image
Shivam

Thanks for correction, done updating. 👊

Collapse
 
protium profile image
protium • Edited

Aliases are also totally needed for productivity 💪🏼. Theses are the ones I use the most:

# checkout or create new branch
ck = "!f() { git checkout $1 2>/dev/null || git checkout -b $1; }; f"

sync = !git pull origin main --rebase
up = !git push -u origin `git branch --show-current`

main = checkout main
Enter fullscreen mode Exit fullscreen mode
Collapse
 
ritamchakraborty profile image
Ritam Chakraborty


git commit -am "Your commit message"

Changed my life. Read more about it here

stackoverflow.com/questions/429896...

Collapse
 
shivam164 profile image
Shivam

Added ✌️

Collapse
 
zaff profile image
Zafer Gurel • Edited

If you're working with a remote repository and want to see the location of this remote repo, the following command might be helpful:

git remote -v

In addition to that, tagging is also a crucial feature of git. So, git tag command is also worth exploring.

Collapse
 
erikgmatos profile image
Erik Garces Matos

Good summary,

A tip:
We also can to put untracked files in stash, like this:

git stash --include-untracked

or

git stash -u

Collapse
 
shivam164 profile image
Shivam

Sure I will be adding it soon. Thanks for suggestion

Collapse
 
nstvnsn profile image
Nathan Stevenson • Edited

Let me introduce you to git reflog!

While git log shows us the repository's public commit history, git reflog (or git reference log) shows us our workplace-specific local commit history.

I'll tell you why this is important.

Ever accidentally mess up a rebase and lose everything in the last few commits? You check you log and there's no trace of the last several hours worth of work to be found? Oops

With reflog, no problemo. It will shown you those commits you thought were gonezo. Run the command, identify the latest commit, make note of the branch tip and run:

git reset --hard my-branch-tip-before-rebase

A sanity saver, for sure. Learned from experiencing my own moment of panic.

Collapse
 
theme_selection profile image
ThemeSelection

Great one...!!

Collapse
 
yolitzr profile image
Yolit Zacarías

Excellent summary!!

Collapse
 
minhaj48 profile image
Minhaj T

really helpful :)

Collapse
 
robsonmuniz16 profile image
Robson Muniz

Great Content, thanks for sharing it🙏
I'm working on a video explaining how to use Git Version control in VS Code.
Happy Coding my friends!

Collapse
 
andrewbaisden profile image
Andrew Baisden

Very good article!

Collapse
 
leeuw profile image
leeuw

appreciated bro 👍.

Collapse
 
zabdeldjallil profile image
Djilou

Awesome post, will surely share it with my co-workers 👌👋

Collapse
 
yongchanghe profile image
Yongchang He

Thank you for sharing this article!

Collapse
 
moose_said profile image
Mostafa Said

Great article! Very useful and informative 👍

Collapse
 
olancheros profile image
Oscar Lancheros

This is a good summary, thanks for sharing. And just as a comment,I think, as someone said below, you have to include git rebase in this post.

Collapse
 
shrihari profile image
Shrihari Mohan

I always use rebase which is a good thing when comparing with pull . Just wanted to add that here!

Collapse
 
shivam164 profile image
Shivam

I will be adding more command to the blog, and will keep in mind about this one.✌️

Collapse
 
atulcodex profile image
🚩 Atul Prajapati 🇮🇳

Really helpful guide thanks for this amazing work Shivam 🙏

Collapse
 
shivam164 profile image
Shivam

Glad I could help 🤗

Collapse
 
cmatt7 profile image
Matt

I never knew how to use git stash before, makes sense to me now, thank you so much!

Collapse
 
shivam164 profile image
Shivam

Glad I could help

 
shivam164 profile image
Shivam

No, I know what it means 😂

Collapse
 
shivam164 profile image
Shivam

Yeah sure I will look into that 👊

Collapse
 
shivam164 profile image
Shivam

Open to suggestions 😊

Collapse
 
mohammedek11 profile image
Data_paradox

Very nice summary ❤️