10 ms·
A simple guide for getting started with git
- MartinCron 15y agoHey pixeldude, there's a lot of negative feedback on here that seems pretty hostile in tone. Don't let it get you down. It's not perfect yet, but you're writing something that I specifically wanted to give others at multiple points in the past. Some constructive criticism: don't align=center absolutely everything, it makes it difficult to read larger sections of text. If everything is centered, then nothing is centered.
- MartinCron 15y agoAnd a little more, I would suggest changing the focus of branches from isolating "features" to isolating "changes" as that's more generalized.
- jheriko 15y agoI got stuck on the setup stage originally. Its not idiot proof enough - like everything to do with *nix and buddies.
- pixeldude 15y agoHey, I think I need to add some more setup instructions. Thanks for your feedback.
- nantes 15y agoNice. I will definitely show this to people who are new to SCM. How about adding Linux install instructions? Something like, apt-get install git for Debian based distros.
- Luyt 15y agoThe tutorial does not mention a Windows GUI for git. There exists TortoiseGit: http://code.google.com/p/tortoisegit/
- pixeldude 15y agoThanks, I'll add that one to the list.
- kruhft 15y agoOne thing that is missing is how to revert your working directory back to a tagged revision. Is that done with checkout?
- zrail 15y agoMoving between refs is almost always done with checkout git checkout tag-name Tags are just a fancy label pointing to a commit so you can use them anywhere you'd use a sha1 or branch name.
- pixeldude 15y agoI'll add that one to the guide as well. Thanks!
- dave1010uk 15y agoOr, if you don't want to keep untracked files: git reset --hard <commit>
- Aga 15y agoPlease note that this does more then what the parent suggests doing by "git checkout". This destroys untracked changes and resets your current branch-pointer to <commit>, removing all the commit-history that comes after <commit>. (You can still recover them from the database, e.g. with "git reflog")
- factorialboy 15y agoI like it. Good start for beginners. I agree that Linux setup instructions are required. Also how to modify the global config.
- ovechtrick 15y agoA 2-3 line "this is why git is useful" at the top would be probably be helpful. I'm forwarding this my friends who are yet to be using version control. Good stuff.
- pixeldude 15y agoThanks, I'll take this into account for an update!
- skrebbel 15y agoI don't get this. Sure, the tutorial looks very pretty, but it does not explain any concepts. "Create a new repository." What is a repository? What do I do with it? The HEAD is a tree "which points to the last commit you've made". Huh? A tree can point? The one in my garden can't. Also, what's a commit? I thought "commit" was a verb, not a noun. And so on. It's nice that people want to make something as complex as git accessible, so I applaud the effort. Nevertheless, this just makes me feel like a moron for not finding it simple. After all, the layout and the pictures make me feel like I should find it simple. But I don't, so it must be me, right? I think it's tutorials like these that keep people on TortoiseSVN.
- pixeldude 15y agoThanks for your feedback! I completely understand your point. Maybe it would make sense to make another guide with an intro on Source Control Management systems and link it in the git guide. Currently, you need to have a little bit of knowledge on an SCM. But I will think about it.
- skrebbel 15y agoHmm, I'm not sure "having a little knowledge on an SCM" does the trick. Let's assume that I've used subversion for years (which surely is SCM). Therefore, for instance, I know that a repository is something on a server that can hold all relevant for my current team (we'll checkout a subdir for each of subproject). Also, I know that committing means sending a change to the server. I also know that I can lock a file and then nobody else can commit it, handy! The meaning of nearly all SCM-related terms in your tutorial are highly git-specific. Making an SCM intro does not really help that. You need to make a git intro.
- pixeldude 15y agoYes, you might be right on this. I will think about it. If you have links where something like this can be found, i would appreciate it. Thanks!
- topbanana 15y agoJesus, I'm stupid not blind!
- nodata 15y agoPlease could you fix pagination so that page down works correctly? (Other sites that use the same format have it working)
- sequoia 15y agoI don't understand; you want page down to go to the next "block"? That would be neat. I'm asking because pagedown seems to "work" as expected on my browser (scrolls down one viewport-height).
- nodata 15y agoYes, next block. (If I remember which other sites do this resolution independently, I'll update my post)
- jasonz 15y agoUsing gitx (http://gitx.frim.nl/ http://gitx.frim.nl/) really helped me grasp some of the concepts you talk about.
- gcb 15y agohttp://stackoverflow.com/questions/1516720/git-gui-client-for-linux http://stackoverflow.com/questions/1516720/git-gui-client-fo...
- calloc 15y agoThat one has been mostly abandoned by the author, for one that is regularly updated take a look at https://github.com/laullon/gitx https://github.com/laullon/gitx which is a fork of the original GitX.
- stingraycharles 15y agoCompletely off-topic, but what tool did you use to create those diagrams?
- pixeldude 15y agoThese are hand-made drawings done with a Wacom Intuos Graphic Tablet.
- stingraycharles 15y agoKudos, they look nice!
- ChrisAnn 15y agoPlease add Git Extensions ( http://code.google.com/p/gitextensions/ http://code.google.com/p/gitextensions/). It's the best Windows Git client I've found so far.
- pixeldude 15y agoI will, thanks!
- manish_gill 15y agoIt so happens that I started using git just 2 days ago. Reading the git help was pretty useful, but I didn't want to spend a week reading pro git(the ebook). This tutorial is pretty useful to get someone quickly up and running, and certainly a better alternative than spending my time learning git (not that I won't study the details as I go along) rather than the actual project.
- g3orge 15y agoI would advice you to read "Pro Git".
- janus 15y agoI have found gitimmersion (1) to be really useful for beginners. (1) http://gitimmersion.com/ http://gitimmersion.com/
- agwa 15y agoYou should mention the "git gui" command alongside gitk. It's a really great way to see the changes in your working tree, stage files into the index, and finally commit. You can even right click on hunks in the diff and select "Stage Hunk for Commit" to stage just parts of a file. Generally I'm a command-line person but git gui is a lot easier to use than "git add -i" Also, git novices whom I know have generally reacted well to git gui.
- graywh 15y agoI particularly like "Stage Line for Commit".
- ThomPete 15y agoI am a designer first and fiddle with programming second. Although I use GIT I am no expertert in it and actually this tutorial made a few things fall in place for me. So for what it's worth, thanks.
- brador 15y agoThe idea is nice, but the implementation is crap. I don't use git but I'd like to. I guess I'm the target market in a sense. The key to simplifying a tutorial is removal of jargon. Just tell it like it is. FYI: This is the line at which I closed the tab: "checkout a repository" - wtf. I don't know what a repository is and now I'm checking it out? is checkout a typo? maybe it should be check-out? either way, I have no way of knowing and confusion has set in. Unfortunately, tab is closed.
- aiscott 15y agoReally? You don't know what a repository is? Or are you just being hypothetically ignorant? I believe that somebody googling git usage is going to be a little bit conversant in the topic of version control.
- jgroome 15y agoWell, we use Git at my work, and I have a vague idea of what a repository is... But not really. I also have to say this: > I believe that somebody googling git usage is going to be a little bit conversant in the topic of version control. So you seriously believe somebody trying to learn about version control will already know about version control?
- aiscott 15y agoWell, you proved me wrong, but a few minutes ago I did believe someone googling about git would know something about version control. For the same reason that I believe someone googling about haskell or erlang probably knows something about programming.
- reinhardt 15y agoAlso someone googling about recursion probably knows something about recursion (e.g. that he is googling for it).
- brador 15y ago
- ljlolel 15y agoI just wrote a post about my even simpler system for using git for people who know SVN/CVS: Teach yourself git in 2 minutes http://www.jperla.com/blog/post/teach-yourself-git-in-2-minutes http://www.jperla.com/blog/post/teach-yourself-git-in-2-minu...
- captaincrowbar 15y agoThanks! This is the best intro I've seen. Maybe now I finally have a hope of figuring out how to use the blasted thing...
- captaincrowbar 15y agoWhat's the point of including instructions for downloading git for MacOSX, when it's already installed in the system by default?
- spacemanaki 15y agoI don't think Git ships with OS X, does it? I think it's bundled with XCode but not with the base OS. http://apple.stackexchange.com/questions/18470/why-is-git-not-found-after-installing-os-x-lion http://apple.stackexchange.com/questions/18470/why-is-git-no...
- captaincrowbar 15y agoQuite possibly; all of the Macs I have on hand already have Xcode installed so I can't check. But I don't think that's a big issue; if you're developing software you're almost certainly going to want to install Xcode and all the accompanying dev tools anyway.
- eigenvector 15y agoWhat is that font and why does it look awful on Windows?
- pixeldude 15y agoIt's a Google Web Font. I'll check that later. Thanks for the hint!
- chrismealy 15y agoThe giant font doesn't make it any easier to understand. Stuff like 'your local repository consists of three "trees" maintained by git' only makes sense to people who already know how git works.
- pixeldude 15y agoI'm always happy about better wording. Any ideas?
- spacemanaki 15y agoI think the problem is that the guide doesn't explain the vocabulary it uses at all. There are programmers (and definitely non-programmers) who might not have heard the word "tree" used to describe a directory filled with files and other directories. It's immediately clear once it's explained, and the guide even has little drawings that look like a directory tree, but for people new to version control and people who have used CVS or SVN this use of the word might be foreign. The same with "commit" since someone coming from another system has a different idea of what that means and someone new to version control has no idea. Honestly, I'm not even sure you need to talk about "trees". The first chapter of Pro Git doesn't mention them at all, and this section describes the working dir, the index and HEAD without using the word: http://progit.org/book/ch1-3.html http://progit.org/book/ch1-3.html Instead he talks about "snapshots" and "stages".
- pixeldude 15y agoI found it pretty helpful with the use of the word "tree" (got it from http://progit.org/ http://progit.org/). But I definitely need to add some kind of glossary to the page.
- dpcan 15y agoExactly. You can use a big happy font, but when step 2 tells me to create a "repository" and I'm already stuck.... well, that's a problem. A repository for what? Is this a folder on my computer somewhere? Should I be moving code into this folder? No idea. In order to make this tutorial helpful, why not take a simple project and get it working under Git? For example, let's say right now I have a folder that consists of a single source code file like testapp.php, a README.txt, and then a content folder with some images in it. How can I take this mini project and start using Git to manage my code? I'm seriously that "beginner" when it comes to Git. I do not understand it at all. Maybe I'm not your audience. This tutorial was FAR from simple IMO.
- jeffreymcmanus 15y agoThanks for putting this together, it looks great. I should mention that the word "shit" in the title of this will make it challenging for me to share this with many professional colleagues.
- calloc 15y agoMac OS X Lion ships with Git by default. So no need to download Git for that platform. Also, brew is a better choice for installing and keeping git up to date.
- paulhauggis 15y agoI wish git (and mercurial for that matter) could properly backup large files. I have some sql files > 100MB that I can't check into source control.
- mkilling 15y agoWhy not? edit: I use git for game development, and we check in some big asset files (uncompressed .wav music tracks etc.). As long as these don't change too often, the repo stays manageable. Up to 10gigs is still a reasonable repository size IMO.
- paulitex 15y agomercurial, as of 2.0, can: http://mercurial.selenic.com/wiki/LargefilesExtension http://mercurial.selenic.com/wiki/LargefilesExtension
- darksaga 15y agoHaving used SVN, and in the process of starting a new job where they use GIT, this actually helped quite a bit. It was quite timely for me.
- zecho 15y agoYou may also be interested in this: http://git.or.cz/course/svn.html http://git.or.cz/course/svn.html
- chadmaughan 15y ago"There's just one thing, Dude. Do you have to use so many cuss words?" -- Big Lebowski Joking aside, there is really no need to ruin a great guide by swearing in the subtitle. I'm not sure I'll ever understand why developers think they need to swear in articles. In this instance, is it because the author is writing in nerd (addressing a seemingly technical concept) and needs to show his article has some universal accessibility by using one of the most understood terms for excrement in the subtitle? I mean, I'm glad he warned me there is no deep poop in the subtitle because I won't read ANYTHING that has deep doo-doo in it. Show some maturity: s/shit/stuff (that'd be Sed for replace the word 'shit' with the word 'stuff')
- jff 15y agoHoly stuff, Batman, you're the guy using the word "doo-doo" unironically while asking adults to "show some maturity".
- chadmaughan 15y agoHehe, sorry. The "doo-doo" was used sarcastically - meant to show exactly how out-of-place it is to talk about excrement (using any synonym) in the context of a git tutorial. Next time I'll be sure and add in my <sarcasm/> tags for clairty.
- mikeheath 15y ago+1
- adrianmsmith 15y agoI think git is not easy to use, and the proof of that is that at least once a month there is a "how to use git" tutorial on the front-page of HN. I'm not saying git is a totally bad system, but I disagree with people who think git is easy to use. You don't see thousands of tutorials on the web, and tutorials hitting the HN frontpage on "How to use Subversion", "My personal Subversion workflow", "My .bashrc file containing my aliases for Subversion". I assert the reason is, that they are not necessary (and not, for example, that nobody uses Subversion, or nobody who reads HN uses Subversion.)
- danneu 15y agoI think tutorials just follow what's hot and what people are using, not necessarily what people have trouble understanding. Git is central to HN as a community, so we upvote things like git articles, and other HNers are more likely to try to learn git because of exposure. Coding projects on HN generally link to a github repository. Someone might create a new git cheatsheet tomorrow, but it doesn't indicate that nobody can understand any of the other git cheatsheets you can find in a google query. See, we also incessantly upvote the latest oneword.js "gimmick", and it'd be inaccurate to assume that these javascript weekend projects fill any sort of demand half the time just because they're so prevalent. I think the community just tends to circulate things that it uses and has an interest in.
- zak_mc_kracken 15y ago> I think git is not easy to use, and the proof of that is that at least once a month there is a "how to use git" tutorial on the front-page of HN. The command line is hard to learn, and there is no real way to learn it besides... well, learning it by heart, quirks and all. A bit like learning a foreign language. After a while, you don't notice it any more and you realize how powerful and pleasant git really is. Here is an article that captures these thoughts fairly well: http://beust.com/weblog/2010/04/06/git-for-the-nervous-developer/ http://beust.com/weblog/2010/04/06/git-for-the-nervous-devel...
- petercooper 15y agoThere were a lot of articles of that sort around back when SVN was interesting and people were bothering to learn it in large numbers. HN wasn't around then, of course, but I remember it sweeping through the Ruby community at the time. SVN has had its wave of tutorials and hype (usually comparing it favorably to CVS at the time). Git's wave still seems to be roaring. When the next system comes out, we'll see tutorials for that every couple of weeks too and Git will be where SVN is now.
- xradionut 15y agoWhy not just download Eric Sink's "Version Control by Example" ? http://www.ericsink.com/vcbe/ http://www.ericsink.com/vcbe/ The book is free or can be purchased and explains both git and Mercurial with similar examples. We use it at our office to get novices up to speed on source control.
- alexholehouse 15y agoIt was available in paperback for free a few months ago too (may still be, not sure). I got it, for free, in Europe. From the states. I have no idea how that works financially, but it's a great book on a number of levels and Eric has my utmost respect because of it.
- sequoia 15y agoThanks for the tip! I just ordered one. There's a lead-gen form you fill out in exchange, but if the book's legit, that's a reasonable price.
- nhebb 15y agoThis is such a great book. No fluff, just straightforward examples of how to do basic version control. Plus, Eric is a good writer. (Actually, anyone who can take a dull topic like version control and make it entertaining probably qualifies as a great writer.)
- ereckers 15y agoIt looks like a lot of people have a case of the Mondays today. Seriously, these are about the number of commands I had sketched out when first starting on GIT, which I assume is your audience. I do have to say that I get a little tripped up between trying to use page-down and having to position the page. A full page side-swipe presentation format would work well here.
- jff 15y agoHow hard is git that we apparently have needed a new "getting started with git" guide every week for the last 3 years?
- MartinCron 15y agoIf it were an easy problem, it would have been solved a long, long time ago.
- manojlds 15y agoIt is neither helpful to an expert, nor to a beginner. A beginner will have no clue what the article is talking, like tree etc. An expert cannot really use this as a quick reference or something. Looks flashy, but is it anything more? I would recommend http://gitimmersion.com/ http://gitimmersion.com/
- sachleen 15y agoI have been using Git for a couple of weeks for my personal projects and got frustrated with it. I literally just finished moving all of my stuff back from Git to SVN before checking HN and reading this. The link you posted is making me have second thoughts and now I want to give it another go. Thanks... I guess.
- DrHankPym 15y agoMake a tutorial that follows the workflow of a bad developer, and you can get a lot of people on board. Show us how to undo terrible mistakes. Show us how to work with other bad developers and working with their terrible mistakes. To get people on board with Git, you gotta show that anyone can use it, efficiently. That's how you get the most number of people to adopt - when they can easily see themselves using and trusting Git.
- therandomguy 15y agoThe biggest problem with Git is the insistence of using command line. Just so you know, when you install the software it provides a simple GUI where you can, you know, click on buttons instead of memorizing commands.
- pors 15y agoI think this guide needs some general explanation of what git is, and what the thinking behind it is (like here: http://progit.org/book/ch1-3.html http://progit.org/book/ch1-3.html). Of course you can get started with this guide, but you have no clue what you are doing. It's learning by following the recipe versus learning by understanding.
- jbp 15y agoFor me the best Git guide is John Wiegley's "Git from the bottom up" @ http://newartisans.com/2008/04/git-from-the-bottom-up/ http://newartisans.com/2008/04/git-from-the-bottom-up/
- danneu 15y agoIn the example where you `git checkout -b feature_x`, I believe you also want to `git merge feature_x` after you `git checkout master`, as the `-d` flag on `git branch -d feature_x` will only delete the branch if it's been merged.
- gnosis 15y agoGit is an ungodly, half-baked, cobbled-together, overcomplicated mess. If it weren't for git's speed and Linus' name attached to it, I'd be shocked to see any experienced developers using it.
- xxqs 15y agono, it's pretty easy to use and pretty consistent if you try to understand its internal logics.
- gigantor 15y agoThis community gets to me on occasion, parallel to that meme with the asian father saying 'Why you no get A+'? I know what git is. I know what source control is. To my knowledge toolbox, you just added an explanation of how a git commit->master is different than a push->remote server. Mission accomplished. Win. Author, please continue executing your work and making this world a better place.
- xxqs 15y agoHere I summarized major differences between Subversion and Git -- I wrote this just to avoid explaining the same things to my customers. I hope someone finds it useful: http://txlab.wordpress.com/2011/12/02/moving-from-subversion-to-git/ http://txlab.wordpress.com/2011/12/02/moving-from-subversion...
- FuzzyDunlop 15y agoI love this, and I've bookmarked it to email it around when I need to, but I'd love to read something that simplifies setting up git on the server side as a central location for repositories. But that aside, coming from SVN it makes sense to me, and I've played around with git without really reading into it too much. It's of added interest because deployment and branching seems much less of a hassle with git than with svn.
- useware 15y agoGit is a decentralized scm. It means there's no concept of a central repository. You can push and pull between any repositories. A good reading is the online book Pro Git which has been mentioned in the comments.
- dbbo 15y agoI don't think this is better than any of the other thousands of git tutorials that any web search would uncover.
- gildur 15y agoAlthough I already learned how to get started in git "the hard way", I think this guide is really helpful for beginners. I know I would have appreciated it. As a matter of fact, the first repo I pushed to github was a guide on how to do do stuff in github =D
- ungerik 15y agoThanks in the name of all visual impaired, but for 30px font is simply to large for me to read.
- tocomment 15y agoIt's weird it says "create a new branch named "feature_x" and switch to it using ..." but it doesn't give you the command to create the branch. Is that a "bug"?
- tocomment 15y agoIsn't pull bad for some reason? I thought you were supposed to use fetch and merge separately. I can't remember why though.
- spacemanaki 15y agoPull is the same as doing fetch and merge individually. It's only "bad" in the sense that it might do something you're not ready to do yet. If you fetch first, you can inspect the changes before you merge them.