DEV Community

loading...
Cover image for 25 Git commands I use daily and you should know

25 Git commands I use daily and you should know

devdefinitive
Just an average Hacker.
Originally published at devdefinitive.com Updated on ・2 min read

Git is a significant piece of day by day programming and is normally utilized in the product business. Since you can utilize many commands, dominating Git needs time. Yet, a few commands are all the more generally utilized. So I will share the most helpful Git commands in this post that each engineer should know.

What is Version Control System

The version control system is frameworks that permit us to add to and oversee various deliveries and phases of a product item without really keeping different documents or folders. They additionally make improvement inside a group more sensible and to a lesser degree a torment as designers don't need to exchange folders, but instead, speak with a solitary source where every one of the progressions is going on and everything is saved.

What is Git?

Git is the most usually utilized VCS. Git tracks the progressions you make to documents, so you have a record of what has been done, and you can return to explicit adaptations should you at any point need to. Git likewise makes cooperation simpler, permitting changes by numerous individuals to all be converted into one source.


Now let's talk about some of the useful Git commands you should know.

  • git add .: adds all the files
  • git commit: records the file permanently
  • git config: it controls set for the local save project/file
  • git help: displays all the necessary information about git commands
  • git status: gives all the information about the current branch
  • git log: get to know about the previous commits
  • git diff: runs a diff work on Git information sources. These information sources can be submits, branches, records and then some
  • git reset --hard: deletes all your uncommited changes | dangerous command lol
  • git remote add <url or address>: to add a new remote address
  • git remove rm: to remove file form Git repository
  • git push -u origin master: for pushing local files to github
  • git branch: the tip of a progression of submits—it is anything but a holder for submits.
  • git checkout: allows you to explore between the branches made by git branch
  • git tag: tags are utilized to check a submit stage as important
  • git fetch: this command advises your local git to recover the most recent meta-information data from the first
  • git rebase: you can take every one of the progressions that were submitted on one branch and replay them on an alternate branch.
  • git config -global color.ui true: see different color on different outputs
  • git init:creates a new git repository
  • git commit -m "New file Readme.md": saves your changes in the local repository
  • git show: that is utilized to see extended subtleties on Git items like masses, trees, labels, and submits.
  • git merge: allows you to take the autonomous lines of improvement made by git branch and coordinate them into a solitary branch
  • git pull <repo link>: to download the folder from the remote repository
  • git stash save: stores modified tracked files
  • git stash drop: discards most recent stashed files

So these are the most supportive git commands I find in my regular programming. There are a few additional things to find out about Git, I will clarify them in a different post.

Discussion (24)

Collapse
mktcode profile image
mkt • Edited

mkdir project1 Srsly?

I mean... is it because 24 didn't feel like a nice number for the title? But without any doubt... it's simply not a git command. :D
But maybe it's worth mentioning that git clone <repo url> <target dir> actually has a built-in mkdir. ;) :P

Collapse
arerex profile image
Arif Zuhairi

this is what I do in my early days, haha..but with experience, you just need to do git clone..the directory will be made automatically, same name as the repo name, unless you wanna it to be different name explicitly

Collapse
ahrasel profile image
AH Rasel Ahamed

only this one I don't know :) : )

Collapse
vishalraj82 profile image
Vishal Raj

It's been summed up nice, but it would have been nicer to put the commands in order. Say first was git init, then git add, then git remote add and so on, as they would be used in real life. Only my personal view of organizing information.

Collapse
shuaib128 profile image
shuaib128

yup

Collapse
christopher2k profile image
Christopher N. KATOYI

Hi ! thanks for the article.
FYI ˋmkdir` isn’t a git command !! It’s an UNIX command

Collapse
erasmuswill profile image
Wilhelm Erasmus

Hey! This is a pretty good cheat sheet to git, apart from mkdir. I have to ask though, do you actually use git reset --hard, git stash drop, and git config -global color.ui true on a daily basis?
Also, would you mind being slightly more consistent with your usage? You use the full specification for git push, but git reset --hard is left to the default?
You have also listed git commit twice

Collapse
devwithzachary profile image
Zachary Powell

As far as a cheat sheet goes... not the worst... but clearly some issues here.

mkdir isnt a git command (hence it doesnt have git at the start of it).
If your really using stash and reset commands daily something is going wrong with your work flow...
Most of the descriptions could have really used more detail... otherwise you might as well just run git help and get the info yourself...

Collapse
damienpirsy profile image
Matteo Vignoli

Agree, many descriptions need a serious rewording, the title is misleading and "mkdir" is an unix command - looks like a beginner discovering git on a Linux machine for the first time

Collapse
phantas0s profile image
Matthieu Cneude • Edited

What about git stash pop or git stash apply? With your set of command you can save to the stash or drop it... but not get it back. The first one remove the entries on the stash, the second keep them.

Other thing: git stash save is deprecated. Use git stash push or the equivalent git stash.

Collapse
nerd profile image
Dhananjay Panage • Edited

Uhhh seems like instead of mkdir you should have chosen git clone, otherwise, it is good.

Collapse
mwrpwr profile image
Joseph Maurer

Thanks for the article! Definitely a good cheat-sheet.

Collapse
ceo53 profile image
Ceo ceo

Wow thanks bro

Collapse
cjsmocjsmo profile image
Charlie J Smotherman

For completeness bzr and svn should have been mentioned.

Collapse
tamsrua profile image
tamsrua

Thank you for this article 👍

Collapse
kamatchipannerselvam profile image
kamatchi

It's very useful

Collapse
jeemok profile image
Jee Mok

tips: try not to run git checkout . before staging your changes

Collapse
arerex profile image
Arif Zuhairi • Edited

maybe need to edit some typo or word, but it's good

Collapse
aidanvon12 profile image
Aidan-von12

Git cheatsheet

Collapse
joshuamwolfe profile image
Joshua Wolfe

Git add -A?

Collapse
matthew_riley_b4b8139bce5 profile image
Matthew Riley

Are you really using all of those commands DAILY?

If you are there’s more wrong with the work than there is with git, or the understanding of git.

Collapse
victoredier profile image
Victor Edier

"How to make people comment on your posts 101"

Collapse
arsalanse profile image
Arsalan Sefidgar

how can I make one commit per PR?

Collapse
arif98741 profile image
Ariful Islam • Edited

you will get command list here for reference.
arif98741.github.io/gitcom