DEV Community

Cover image for Git: the basic commands every developer should know

Git: the basic commands every developer should know

Heather Parker on April 01, 2023

Git is useful for anyone who writes code or tracks changes to files, from web developers to app developers. So, what exactly is it, and why should ...
Collapse
 
sergeyleschev profile image
Sergey Leschev • Edited

I believe you did an excellent job explaining Git and its main components. Their list of 10 essential Git commands is very valuable for beginner developers.

Collapse
 
justplegend profile image
JPL

This is good article, but also beside this, I think it's important to understand and different things you need to do on local computer (own laptop) and GitHub.
On this link it's little bit explained that things: local computer vs GitHub

Collapse
 
swordheath profile image
Heather Parker

Completely agree! Thanks for valuable sourceπŸ‘πŸ»

Collapse
 
swordheath profile image
Heather Parker

Thank you so much, Sergey!

Collapse
 
hanibikdeli profile image
HaniBikdeli

awesome article, but i would also add git fetch

Collapse
 
surbhidighe profile image
Surbhi Dighe

Good Job!!

Collapse
 
mattiasfjellstrom profile image
Mattias FjellstrΓΆm

I agree that with these commands you can live a whole life with git (if you are lucky, at least). I saw that someone else mentioned git switch, but I'd like to chime in on that command. The purpose of git switch is to switch between branches, or create new branches. All you can do with git switch you can do with git checkout, but git checkout has a lot more use-cases so it is like using a sledgehammer for small nails! :)

Collapse
 
soderluk profile image
K.S.

A couple of commands I've been using a lot since they came out, is git switch [-c] <branch> to switch to another branch (or create one with -c), and git restore <files> for restoring working tree files. Adding --staged to git restore will just restore the index, i.e. un-stage files.
These two were introduced so there's a distinction between switching branches and restoring the index, which can be achieved by the git checkout command.

Collapse
 
bcouetil profile image
Benoit COUETIL πŸ’«

Hey ! I would replace git init with git reset (because you already have git clone). Hard to live without it.

Collapse
 
bybydev profile image
byby.dev

If you want to create an alias named "lg" that shows a history of all commits, you could use the following command:

git config --global alias.lg "log --all --graph --decorate --oneline"
Enter fullscreen mode Exit fullscreen mode
Collapse
 
shabink profile image
Shabin-k

thank you

Collapse
 
timmcwilliams profile image
Tim McWilliams

Wish I could figure out how to use my VS Code interface to correctly use my repositories.