DEV Community

Learn git concepts, not commands

Nico Riedmann on June 02, 2019

An interactive git tutorial meant to teach you how git works, not just which commands to execute. So, you want to use git right? But you don't j...
Collapse
 
ben profile image
Ben Halpern

Learn x concepts, not x commands. Probably a reusable statement across many technologies.

Collapse
 
bugtester46 profile image
bugtester46

TEST

Collapse
 
hermeshcg profile image
Hermes Caretta

teste

Thread Thread
 
ben profile image
Ben Halpern

Toast

Collapse
 
jrop profile image
Jonathan Apodaca

This reminds me of the site "learn X in Y minutes". I visit that site every few days haha

Collapse
 
thikthik profile image
Karthik Ramaraju

Learn x concepts, not only x commands.
Probably a Best reusable statement across many technologies.

Collapse
 
michaelscheffenacker profile image
Michael Scheffenacker

How about just:
Learn concepts, not commands.

Thread Thread
 
thikthik profile image
Karthik Ramaraju • Edited

Still we need to learn commands but not only commands. So Learn Concepts , not only Commands :)

Collapse
 
bugtester46 profile image
bugtester46

test

Collapse
 
aranouski profile image
Artsiom B

For many years trying to combine learning and writing code I decided that copies from stackoverflow is the best part of my job :D

Collapse
 
pshchelo profile image
Pavlo Shchelokovskyy

Nice post, thanks.

For another perspective I could also suggest the "Git from the Bottom Up" jwiegley.github.io/git-from-the-bo...
which starts from how the repo is built inside (blobs and trees). Opened my eyes at some point - and also allowed me to explain Git to others better :-)

Collapse
 
unseenwizzard profile image
Nico Riedmann

Thanks, did not know that one yet! Added to my reading list

Collapse
 
placideirandora profile image
Placide IRANDORA

One of the best articles about Git. You've really put a lot of effort in producing this awesome article. Thank you so much for your contribution to the developer community. Actually, This is the best and intensive article that I have ever encountered on the internet. Nice job!

Collapse
 
parkerholladay profile image
Parker Holladay

Great write up on crucial concepts to understanding how/why to use various git commands. There is one semantic distinction that I find helpful when talking about rebase to those unfamiliar with it. Rather than saying:

We re-base our add_patrick branch on the current state of the master branch.

It might be clearer what is happening if you say:

We re-base our add_patrick branch from the current state of the master branch.

That is to say, we get a new base set of commits for our branch from another branch. So, as you describe, when we run the command git rebase master [add_patrick], we are taking all commits from master that add_patrick does not yet have, and rewinding to apply them to HEAD before replaying our commits in add_patrick.

Collapse
 
unseenwizzard profile image
Nico Riedmann

For me personally understanding the on or onto wording for rebase as it's also used in the git reference actually helped me when I learned about it originally.

I take my changes, which where originally based on some branch HEAD, and I put them onto some other branch's current state (or state of the same branch)

Collapse
 
parkerholladay profile image
Parker Holladay

Like I said, it is semantics, but I've found that slight change in wording useful for some when helping them understand rebase.

Thread Thread
 
wobuyaotweet profile image
Not Real • Edited

Agreed - I completely misunderstood this at first because โ€œrewind and rebase ontoโ€ sounds like โ€œtake my work from โ€˜add_patrickโ€™, add all those commits โ€œontoโ€ โ€˜masterโ€™ (which doesnโ€™t happen & wouldnโ€™t really make sense) before moving the divergence point & continuing on the current branch.

The key point to understand is that you get all new commits from โ€˜masterโ€™ so your current branch is up to date with it (kinda like a git pull), then reapply the commits from โ€˜add_patrickโ€™ again from that new point of divergence from master, but still on โ€˜add_patrickโ€™ itself.

That confusion on my part aside, I found this to be a fantastic overview! Thanks!

Collapse
 
naurel1467 profile image
Naurel1467

Now i get it...thanx

Collapse
 
angelarae63 profile image
Angela Whisnant

Hey! I am so new to GitHub...where am I supposed to be typing these commands...at the command prompt, possibly? I am trying to follow this tutorial. I ran into a 'GitHub Desktop.' Now I'm confused as to whether I use this or do it some other way.
Sorry!
Angie

Collapse
 
unseenwizzard profile image
Nico Riedmann

Hi

Yes, those go in the command line!

There a few graphical git clients that I hear are nice. The github desktop one, tower git and a lot of my colleagues use what comes with their IDE (we use intellij idea for java)

But for understanding what is going on I think you'll learn more using git from the commandline.

The tools abstract a lot of things away trying to make things easier to use

Collapse
 
angelarae63 profile image
Angela Whisnant

I think I prefer the command line anyway. Thanks so much!

Collapse
 
andrewmcodes profile image
Andrew Mason

This is crazy good. Super informative and the visual aids definitely help. Thanks for sharing! ๐Ÿ‘๐Ÿผ

Collapse
 
prahladyeri profile image
Prahlad Yeri • Edited

One caveat you should mention is that "git push" doesn't always work on some git installations, especially POSIX ones like Linux. You may have to qualify with the remote repository for it to work:

git push origin master
Enter fullscreen mode Exit fullscreen mode

But otherwise, its super informative and well written article.

Collapse
 
unseenwizzard profile image
Nico Riedmann

With git 2.0 introducing the simple push strategy as default setting, I was under the impression that you generally wont need to qualify the remote you're pushing to, as long as it's set as upstream and has the same name as your local branch (which it is if you don't go out of your way to have it differently).

Or am I wrong about something there?

Collapse
 
prahladyeri profile image
Prahlad Yeri • Edited

Yep, it considers the current branch (origin/master) as the default if git config --global push.default setting is set to current. This is usually set by default on windows and ios, so simply doing "git push" might work but on some linux distros, this setting isn't set to current but set to nothing instead (which means you'll have to explicitly add the branch).

Especially, the last time when I'd worked on Ubuntu, simply doing a git push had not worked.

Thread Thread
 
unseenwizzard profile image
Nico Riedmann

As far as I understood it, the "new" (git 2.0 is from 2014) default is simple.

From the git doc:

When neither the command-line nor the configuration specify what to push, 
the default behavior is used, which corresponds to the simple value for push.default: 
the current branch is pushed to the corresponding upstream branch, but as a safety measure, 
the push is aborted if the upstream branch does not have the same name as the local one.
Enter fullscreen mode Exit fullscreen mode

Of course it may still be that some distro installations either install older versions, or install with a non-default configuration. Somewhat recently having set-up my work laptop on Ubuntu 18.04 I do not recall having to set the push configuration

Thread Thread
 
bugtester46 profile image
bugtester46

TEST

Collapse
 
jamesanderson13 profile image
JamesAnderson13

Very interesting information, I really like it because it can add insight for me more broadly, thank you very much for this extraordinary information

tutu app

Collapse
 
voidjuneau profile image
Juneau Lim

What an effort you have put on this post. It's almost felt bad to call it as a post. It seems like a book or wiki very least.
I was just getting there by doing it and you helped me greatly. I also really loved the useful tips. Thank you so much.

Collapse
 
biros profile image
Boris Jamot โœŠ /

Wooh! Did your post really get more than 3000 reactions in only two weeks?

That's awesome, congratulations!

Now I have to read it...

Collapse
 
spearkkk profile image
spearkkk

Thanks for nice writing. It is awesome for understanding git to me.
And I want to share with my friend and colleague, Could I translate with my language and share it?
I will refer this origin post too.

Collapse
 
unseenwizzard profile image
Nico Riedmann

What a great idea, please do that!
The more people it gets to help the better.
What will you be translating it to?

I guess you'll want to fork the git project so you have the md source for your translation.

I'd be more than happy to link to your translation as well, or include it as branch of the repo when you're done!

Collapse
 
reddyaravind178 profile image
aravind_reddy • Edited

One of the best tech articles I have ever read. Thanks for the effort

Collapse
 
irshadbluecast profile image
Irshad Bluecast • Edited

Awesome. A great in-depth tutorial.
Just one note - instead of git checkout command you could use git switch command, which is easier to change branches in git and also aligns with the concept of switching and the command for it.

To read my tutorial with more detailed examples on how to use git switch command, please visit -dev.to/irshadbluecast/how-to-switc...

Collapse
 
bberrycarmen profile image
Rachel M. Carmena

Congrats Nico!

I've added a bonus at the end of the post which inspired you.

I'm really happy ;)

Collapse
 
unseenwizzard profile image
Nico Riedmann

Wow. Thanks!

For the shout-out in your article, the inspiration and your great articles in general :)

Collapse
 
aoifecarrigan profile image
Aoife Shannon

This is the tutorial I needed back when I first started out with git as a junior dev, I struggled way too long just learning off commands rather than trying to understand the concepts, will be bookmarking for future thank you!

Collapse
 
lyphanna profile image
Phanna ๐Ÿ”ฅ

Great article!

Collapse
 
dgiulian profile image
Diego Giuliani

Great Article! I really loved it. Could you add a section about the reset command?. The different options it has and the difference between them

Collapse
 
gede_73 profile image
Fersu

Hi there! Nice post.

I think that you've made a mistake here:

"Should you ever realize in the middle of resolving conflicts that you actually don't want to follow through with the merge, you can just abort it by running git commit --abort"

I think you probably wanted to write: "git merge --abort".

Collapse
 
unseenwizzard profile image
Nico Riedmann

Thanks!

Yes, I did mean merge and have fixed it. Thanks for catching that!

Collapse
 
limidiassociais profile image
Lilian Lima

Nico, I'm writing a serie about git behind the scenes and I'm using this post as a reference for this writing.Thank's for this material!

Collapse
 
fenchu profile image
fenchu

I do not understand local repo. You have a local clone and several staging which are just different tagged revisions of the remote repo. If there are more than one user you need to keep everything in the remote repo and push/pull frequently. short lived branches etc. but everything lives remotely. Not a single add without an immediate push.

And the remote servers like gitlab/gogs handles conflict by leaving a pull request for the admin to accept/reject, much better than rebasing long lived branches with outdated code :-)

Collapse
 
parkerholladay profile image
Parker Holladay

I do not understand local repo.

When working with a clone of some remote repository, what you have is a git repository on your local machine that is a copy of the remote at that point in time. All work you do is in your local repository, which, to your point, you should constantly keep in sync with the remote repository.

Also, I agree 100% with not wanting long-lived branches, but rebase and merge (and their differences) are very important concepts to understand in git. You can't

keep everything in the remote repo and push/pull frequently

without doing a merge or rebase at some point, whether implicitly or explicitly. Every pull from remote causes a merge of some sort. All commits, including pull requests (when accepted), have to be merged into your trunk somehow--whether with a merge commit, or by being rebased then merged. The author does a great job of illustrating the distinctions and benefits of both.

Collapse
 
steffenpedersen profile image
Steffen Pedersen

Great post! But you have some markdown formatting errors ๐Ÿ˜ƒ

Collapse
 
unseenwizzard profile image
Nico Riedmann • Edited

Oh, thanks for pointing that out! Completely missed those!

I've applied a quick fix to at least make these parts readable, but I'm really unsure as to why those parts don't work.

All of them are multi-line code blocks with three back ticks

    `` `
    {code}
    `` `
Enter fullscreen mode Exit fullscreen mode

However only the first few seem to work (here? both on github and my blog those are rendered fine).

Does anyone have an idea what might be wrong?

Collapse
 
steffenpedersen profile image
Steffen Pedersen

Did you get it to work properly? There is a space in the three back ticks. Maybe that is the problem ๐Ÿ˜ƒ

Thread Thread
 
unseenwizzard profile image
Nico Riedmann

Didn't figure it out at all yet...
I've changed to having 4 spaces as indentation and that somehow results in things at least being rendered as individual code lines, but not as the block

Put the space in the sample above, because I didn't know a way to escape the back-ticks inside the code-block to show how they actually are..

Collapse
 
yourdevguy profile image
Mike Haslam

Nico thanks so much I never took the time to really understand how Git works, then I googled when I messed up. You are so right about how important it is to understand how things work. No wonder we get in trouble when we Willy Nilly cut and paste code. Super Cool of you to share this brother!

Collapse
 
mazgajmaciek profile image
Maciek

Hi Nico, I'm a bit lost on how rebase works under the hood:

  1. So first it goes to the common ancestor
  2. Applies all the commits made on add_patrick branch to master
  3. From this then it finally creates a new commit on add_patrick branch that incorporates all the changes it previously merged with master (point no 2) to the branch

Am I getting this correct? :)

Collapse
 
arturogascon profile image
Arturo Gascรณn

Great effort of you explaining these concepts, I think its quite frustrating when one is starting out as a developer to learn these things but they are quite valuable and needed so we find articles like this one very useful.

Thank you very much, Nico ;)

Collapse
 
laszl0 profile image
laszl0

Thanks!

Collapse
 
bugtester46 profile image
bugtester46

EXIF TEST

Collapse
 
schliesserio profile image
Philipp Schliesser

Great article! Thanks for all the work you put into this.

Collapse
 
chancedev profile image
Chance

Like everyone else, I have to say this was fantastic. Thank you! I'm comfortable w/ git, but I tend to stay in the areas I'm comfortable in (so maybe I'm not that comfortable w/ git? ha). I learned so many more things and solutions to problems I have come across. Great work!

Collapse
 
alaskaa profile image
Sibylle Sehl

Such a great article! Thank you for such a concise and nicely written post on some of the concepts of git - will certainly share it with others that are attempting to understand git and demystify some common questions!

Collapse
 
techwithrajesh profile image
techwithrajesh

thanks, this was very informative!!

Collapse
 
lukewduncan profile image
Luke Duncan

Holy **** dude. This is an awesome post! Thanks for writing

Collapse
 
amineamami profile image
amineamami

great job

Collapse
 
mobidi profile image
Mobidi

I'm saving the commands anyway but now I understand them, so many thanks !
Git has so many subtleties.

Collapse
 
chinchang profile image
Kushagra Gour

Great post and well said. Along the same lines, I started "Build GIT, Learn GIT" -> kushagragour.in/blog/build-git-lea...

Collapse
 
mfboulos profile image
Michael Boulos

It's actually ridiculous how helpful this entire post is. Thanks for the work you put into this! Definitely shed some light on git concepts I wasn't all too familiar with.

Collapse
 
jannikwempe profile image
Jannik Wempe

After reading lots of articles here, this is my first comment. I really have to thank you for that awesome work! You are my first unicorn :-)

Collapse
 
oferk1 profile image
oferk1

Unbelievably helpfull in understanding core concepts

Collapse
 
sbn78 profile image
sbn78

Great post, very straightforward and informative!

Collapse
 
danjconn profile image
Dan Conn

I love this so much! It's so true too, and as Ben said is great advice across many technologies!

This definitely needs sharing! Thanks!

Collapse
 
bezpiecznyvpn profile image
Pawel Sekuratywny

I love this, we definitely should learn about concepts and ideas

Collapse
 
lhmzhou profile image
Linda Zhou

Great read --- thanks for sharing!

Collapse
 
rdgutierrez profile image
Ruben Dario Gutierrez Sanchez

Thanks for this post, very clear and usefull

Collapse
 
izulien profile image
James Daniel

This post is amazing and highly recommended bookmark to anyone using git.

Thank you for your time and effort on this article and for writing in an informative and engaging way.

Collapse
 
carlashub profile image
Carla Goncalves • Edited

This is one of the best tutorial articles I've read. You are a great teacher. I hope you write some more I'll be in the look out! Thank you

Collapse
 
unseenwizzard profile image
Nico Riedmann

Thanks :)

Glad you found it helpful!

Sadly I'm a horribly slow writer, but I have a few things I'm working on

Collapse
 
pmaingi profile image
pmaingi

A very nicely written tutorial. Thanks for sharing.

Collapse
 
wizardrogue profile image
Joseph Angelo Barrozo

This! This is the best git article/lecture I've encountered throughout my 8 years of web development!

Collapse
 
flrnd profile image
Florian Rand

Wow, this is super helpful! I've been looking for something like this for months!

Thanks!!

Collapse
 
taragrg6 profile image
taragurung

Best

Collapse
 
xluos profile image
ๅพๅธ…ๆญฆ

Great article, can I translate and reprint it

Collapse
 
eryisan profile image
eryisan
Collapse
 
sharadsrivastavahyd profile image
sharad-srivastava-hyd

A piece of art for git understanding.. Excellent

Collapse
 
nobozo profile image
Jon Forrest

Minor typos:

"on it's own" -> "on its own"

There are ~3 other "it's" vs. "its" errors.

Collapse
 
unseenwizzard profile image
Nico Riedmann

Thanks for catching those! Guess not being a native speaker has to show somewhere.. ;)

Given that there were actually quite a few more and the formatting is off if I just copy-paste the markdown here for some reason, I've only fixed the mistakes in the git repo of the tutorial

Collapse
 
airbr profile image
Morgan Murrah

Appreciated the effort that went into this

Collapse
 
hemantgovekar profile image
Hemant Govekar

Awesome article !!!

Collapse
 
joewilson0 profile image
Joe Wilson

Excellent article, Nico!

Collapse
 
samir092 profile image
HassenSamir

Amazing tutorial ! I found this tutorial very easy to read and really instructive. I learned so much thanks to you ๐Ÿ‘

Collapse
 
prafulla-codes profile image
Prafulla Raichurkar

Great article, would love to have some gifs in it for better understanding ๐Ÿ˜„

Collapse
 
unseenwizzard profile image
Nico Riedmann

Anything in particular you got in mind there, where you think it would help?

I've been thinking about turning it into a mix of presentation and hands on tutorial at some point.
And maybe when I do that, the visuals might be something I get around to improving.

Collapse
 
siddharthshyniben profile image
Siddharth

Looks like this article broke?

Collapse
 
jannikwempe profile image
Jannik Wempe

Thanks for that awesome article! This not only is my first comment, but also my first unicorn :-)

Collapse
 
buginit profile image
buginit

Believe me, this is not 36 min read, I'm a human and it took me a few days.
But this is a great post.

Collapse
 
jcklpe profile image
Aslan French

Excellent tutorial man! This was super well explained.

Collapse
 
rta_ind profile image
Real Time Academy • Edited

Could some one explain What sequence of Git commands
could have resulted in this commit graph?

Collapse
 
rta_ind profile image
Real Time Academy • Edited

Could some one please explain What sequence of Git commands
could have resulted in this commit graph?
dev-to-uploads.s3.amazonaws.com/i/...

Collapse
 
sunflower profile image
sunflowerseed • Edited

this is the exact opposite of "pragmatic programming", which is, "just do this and it should work and don't ask why and even I don't know why and how it works and what it is but just do it."

Collapse
 
dehigas profile image
Rajitha Prashan

Awesome Post Thanks !! This is the best article I found on the internet. Helped me a lot !

Collapse
 
brunopscavalcante profile image
brunopscavalcante • Edited

I haven't read the entire article (yet), but it's been a wonderful tutorial so far. Git's documentation is very dense, and thus confuse most of the sometimes. Thanks!

Collapse
 
unlock2020 profile image
Unlock 2020

LeonFlix for windows is a free multi-platform content streaming app. The app is available for a number of platforms excluding Android.

Collapse
 
thefluxapex profile image
Ian Pride

Awesome article; truly appreciate it. Definitely bookmarking this for reference.

Collapse
 
bugtester46 profile image
bugtester46

test

Collapse
 
arvindpdmn profile image
Arvind Padmanabhan

Awesome. Shared it on Devopedia twitter handle.

Collapse
 
ben profile image
Ben Halpern

Truly fabulous post!

Collapse
 
zawawimanja profile image
zawawimanja

Eventhough is it long , this tutorial is good when you tell the reader by using the picture. Now I understand the concepts and flow. Thanks you very much.