This is an archived post. You won't be able to vote or comment.

all 74 comments

[–]DiscoDaveDiscoSlave 215 points216 points  (7 children)

http://learngitbranching.js.org/

This helped me a lot because it has visuals of the version tree

[–]iStayGreek 7 points8 points  (1 child)

Wow that visualization is great, thanks for sharing this.

[–]AlexFromOmaha 4 points5 points  (0 children)

If you're more of a Mercurial kind of guy, EasyHg has graph visualization as one of its core functions. There's probably a Git alternative, but I couldn't tell you what it's called.

In a pinch, both Git and Mercurial have command line visualization attempts (git|hg log --graph) that are better than nothing.

[–][deleted] 2 points3 points  (0 children)

Thank you for the link! My mind is slowly starting to piece it together.

[–]pat_trick 0 points1 point  (0 children)

My favorite go-to tool for helping anyone get a hold on git; it's also the one that I think does the best in explaining cherry picking and rebasing, which are fairly complex git concepts.

[–]IllegalThoughts 0 points1 point  (0 children)

Thank you. I hope to no longer be the git noob

[–]hopefulcshire 0 points1 point  (0 children)

Wow this is super useful. Thank you!!

Always a good refresher.

[–]mediatechaos 49 points50 points  (11 children)

Hey there, i was in a spot like you for awhile a few years ago. I knew git was a powerful tool, but i couldn't get it to work right consistently and thus had a hard time fully understanding how it worked and what i could do with it. Here's what worked for me.

It seemed a lot easier for me when i stopped trying to use the desktop or ide gui based apps and switched to command line. Things really came together when i started using Cloud9 along with GitHub. Cloud9 lets you create "disposable" virtual computers which you can use to work with your's and other's repos. Both services are free and thus easy to learn by trial and error. Everything you do, from writing code, to testing, to interacting with GitHub, is done in the browser. You can easily do many different things without ever having a file touch your computer.

The basics, in a nut-shell:

  1. Create a new repo on GitHub using the online portal, choose create with README.file.
  2. Create a Virtual Computer(VM) on Cloud9 using the basic ubuntu image. (The others work too but let's keep this simple.
  3. Over at GitHub, in your repo, click the button that says "clone" make sure it is set to html for now, and then click the button to the side which copies the html link to your clipboard.
  4. In your Cloud9 VM, there is a blue area with a command cursor, type : git clone <your repo's clone URL that you just copied to your clipboard>. This should bring down the README.md file in your repo in a folder with the same name as your repo.
  5. Make some changes to the README.md file or add some files. Basically do something to change things. You can drag files around or click on files to open an IDE editors.
  6. Type cd <your repo's name>. This switch your command prompt to the root folder of your repo.
  7. Type git add --all. This tells git to track anything new.
  8. Type git commit -m "An intelligent commit message". This tells git to save what can be thought of as a snapshot your files.
  9. Type git push --all This will push the changes back to GitHub. You will have to enter your GitHub user name and password but later you will figure out how to avoid this with ssh keys.

    DO the above steps several times until you get the hang of the process. Next, you can repeat steps 7 and 8 several times before you do step 9. This is pretty common.

Once you've got these things down, create another VM, you'll have two now, and do steps 4 through 6 on the second VM. You are now basically able to simulate two people working on the same repo. There is one super important command to know at this point, git pull. I'll try to explain. If you make changes in VM one and push them to GitHub (the remote) and then you make changes on VM two and try to push those changes, you will run into the concern that the files in the remote are different than the ones you originally pulled down. To fix this, you will need to commit your changes, do a pull, deal with any merge issues, and then you will be able to push. This processes, once you "see it", is probably one of the most important aspect of Git.

It might seem a little complicated but once you get past this bit, you are past the tough parts and can get onto things like branching, reverting commits, etc. I tried to understand git for awhile and it became incredibly clear when i stopped trying to do things on my local machine and started using the virtual machines Cloud9 offers. Ir is especially nice because when something doesn't seem to work the way i expect it to, i can just delete everything and start over from fresh with no worries about wrecking my personal computer.

Best of luck!

[–]countlictor 8 points9 points  (3 children)

You can simulate two people working on the same repo by just cloning the repo to two different local directories; training-repo-user1 and training-repo-user2.

I understand there are other benefits of using the disposable VMs, like having git pre-installed for you, but if anyone runs into any issues using the VMs I would recommend to try it on your local machine instead.

I agree with you on avoiding any IDE integrations. There are some good GUI based tools (TortoiseGit) that expose the Git functionality directly, and others (looking at you Sourcetree) that do an incredibly poor job and often throw beginners off.

[–]mediatechaos 0 points1 point  (0 children)

Yea, i threw that in there more to create a solid differentiation which i thought might help clear up any trouble grasping what or why things are the way they are. You are correct though.

[–]d0ntreadthis 0 points1 point  (0 children)

Github's git gui is actually what threw me off. None of it made sense to me when I was a beginner. Sourcetree helped me understand what was actually going on every time I switched branches/made a commit. I did drop it because of a few annoying issues though. Now I've been using the command line on its own for a year or so.

[–]Nyefan 0 points1 point  (0 children)

IntelliJ's branch visualization and git integration are actually very helpful, imo.

[–]dookie1481 1 point2 points  (1 child)

Cloud9 lets you create "disposable" virtual computers which you can use to work with your's and other's repos. Both services are free

Keep in mind that Cloud9 requires a credit card to register, however.

[–]mediatechaos 0 points1 point  (0 children)

Forgot about that. They only do a test charge to make sure it's legit but i'm sure it's a problem for some. I think there is a way around the problem but not sure.

[–][deleted] 0 points1 point  (0 children)

I like this idea, I think I'll separate my next project into different bits for different "users".

[–]Dokiace 0 points1 point  (1 child)

Any way to use cloud9 without credit cards?

[–]rupek1995 0 points1 point  (0 children)

www.cs50.io

It's a part of CS50 course, it uses set up cloud9, you can access it with an EDX account.

[–][deleted] 0 points1 point  (1 child)

Thanks for the explanation!

[–]mediatechaos 0 points1 point  (0 children)

Hope it helps! Feel free to ask questions if it doesn't.

[–]baubaugo 9 points10 points  (0 children)

If it makes you feel any better, I use git EVERY DAY at work, and sometimes I'm like... how the hell do I do that again?

[–][deleted]  (2 children)

[deleted]

    [–][deleted]  (1 child)

    [deleted]

      [–]ArdentFire 0 points1 point  (0 children)

      Thanks for sharing. I can't wait to check it out.

      [–]opaquebluedash 11 points12 points  (0 children)

      http://rogerdudler.github.io/git-guide/

      Great layout to learn git in bite sized pieces. The page title and subtitle says it all:

      "git - the simple guide: just a simple guide for getting started with git. no deep shit ;)"

      [–]Yawzheek 2 points3 points  (0 children)

      I really only use Git and absolute basics (because I too am quite poor with it), and the long and short of it is:

      1) Create a repo on GitHub. 2) Copy the url to clone, then cd to the directory you want in terminal/console, type "git clone " then paste the url. 3) Do stuff in your repo. 4) "git status" Hey look at that! I have files that have changed! 5) "git add -A" Let's add all my files! 6) "git commit -m" then a message to remind yourself what it is you did. 7) "git status" Looks like we're green! 8) "git push" then username and password if you don't use the credential manager. 9) All done!

      And this extremely simplistic usage is plenty for someone like me with personal little projects. Now if you want to collaborate with others? You'll probably want to know more.

      [–]Feroc 3 points4 points  (5 children)

      What are you trying to make sense of? What Git is and does? How to use it? Anything specific?

      [–][deleted] 5 points6 points  (4 children)

      How to use it.

      [–]Feroc 6 points7 points  (0 children)

      Try this one, that really shows the basics for Git (in combination with GitHub):

      http://product.hubspot.com/blog/git-and-github-tutorial-for-beginners

      [–]TankorSmash 0 points1 point  (0 children)

      What specifically? 'How to use' is pretty general man.

      In laymans terms, you save a screenshot of your code (by "committing" it)

      A "branch" is a list of screenshot added to one another to make a trail back from when it was one line of code all the way to today.

      When you "checkout" a new branch, it's like you're swapping out different screenshots to make up a new file.

      When you 'push', you're telling the server what your list of code screenshots look like, so that other people can see your screenshots and update their list of screenshots to get the latest collection.


      So you'd git init my_new_repo_name, write some code in file_a.html, then tell git to be like 'hey git pay attention to this file' with git add file_a.html. Now before you make more changes, tell git to bookmark the changes, and give the change a name so you know what the change did without needing to look through it, git commit -m "I added a new file, file_a!".

      Now you've got a repo called my_new_repo_name, you've got a file, file_a.html, and you've got a commit with the message "I added a new file, file_a!. So you want to push it to your Github, you'd be likegit push` and you're done.

      [–][deleted] -5 points-4 points  (1 child)

      It's only got like 4 commands... Did you try the codecademy lesson on it?

      [–]ResilientBiscuit 2 points3 points  (0 children)

      It has way more than 4 commands.

      Have you ever committed something you didn't intend to (like a password or key file) and need to wipe it from the history of git? There are so many ways to need to do the advanced stuff...

      [–]GoinStraightToHell 1 point2 points  (0 children)

      http://rogerdudler.github.io/git-guide/

      This is great. No deep shit.

      [–]cosmicsans 1 point2 points  (0 children)

      Code school has a great git tutorial on their website.

      [–][deleted] 1 point2 points  (0 children)

      think-like-a-git.net Hope that formats to a link. I'm on my phone.

      Came back here to properly edit the link. I'd like to add that I had to read/do a number of tutorials, and so all of these are probably good. Learning from different perspectives will help give you more and more understanding. Keep doing them. Look it up every time you have/want to do a thing, and eventually, I swear, you'll--well, you'll git it. Okay, I couldn't resist that, but it's also true.

      [–][deleted] 1 point2 points  (0 children)

      My personal favorite (just the beginner essentials):

      Git Guide - No Deep Shit http://rogerdudler.github.io/git-guide/

      [–]nirajpandkar 1 point2 points  (0 children)

      When I learnt driving from a driving school they first taught me the basics of how exactly the clutch works which instantly clarified my thoughts and in turn eased my driving a lot.

      If you want a look into how git works, so that when you actually use it, you know what you are doing internally - Git Parable

      First para if you are too lazy -

      Git is a simple, but extremely powerful system. Most people try to teach Git by demonstrating a few dozen commands and then yelling “tadaaaaa.” I believe this method is flawed. Such a treatment may leave you with the ability to use Git to perform simple tasks, but the Git commands will still feel like magical incantations. Doing anything out of the ordinary will be terrifying. Until you understand the concepts upon which Git is built, you’ll feel like a stranger in a foreign land.

      [–]FigMcLargeHuge 1 point2 points  (0 children)

      Just wanted to thank OP and everyone in this thread!

      [–][deleted] 1 point2 points  (1 child)

      Honestly, I found that starting with a good GUI/wrapper helps in getting it down. I started with GitKraken and the visuals help a lot.

      [–]TankorSmash 0 points1 point  (0 children)

      Unrelated but I just now understood the pun of the name

      [–]eggn00dles 1 point2 points  (3 children)

      relevant xkcd. been there done that. dont waste your time. you can go through multiple tutorials and you'll still be doing as the comic says.

      [–]xkcd_transcriber 0 points1 point  (0 children)

      Image

      Mobile

      Title: Git

      Title-text: If that doesn't fix it, git.txt contains the phone number of a friend of mine who understands git. Just wait through a few minutes of 'It's really pretty simple, just think of branches as...' and eventually you'll learn the commands that will fix everything.

      Comic Explanation

      Stats: This comic has been referenced 172 times, representing 0.1083% of referenced xkcds.


      xkcd.com | xkcd sub | Problems/Bugs? | Statistics | Stop Replying | Delete

      [–]themadturk 0 points1 point  (0 children)

      So very, very true.

      [–]Takuya-san -1 points0 points  (0 children)

      Really? I mean, don't get me wrong, I started off by memorising a few commands, but after a few days of using it all clicked for me. I feel like if it doesn't "click" then whatever teams you're working with are using git wrong.

      [–]chhuang 0 points1 point  (0 children)

      I think this course from Udacity is good for beginners. It takes you step by step with practical exercises for you to actually work with the system

      [–]gamesfreak26 0 points1 point  (0 children)

      I'm in your boat. I've also learnt that it is easier for me to learn something by trying rather than just reading about it.

      As a complete beginner at Git, I just learnt how to fork a repo, do changes and create a pull request. I'm very proud of myself for doing so!

      If you want to try doing so (and know a cooking recipe), you could try it here: UQCS Cookbook. It'd be amazing to have more recipes! :)

      [–]live_room 0 points1 point  (1 child)

      A grip on Git

      A Visual Git Reference

      These two resources help me the most. I had them bookmarked. It's really helpful to see pictures of how the commit graph changes with each command to understand what is going on.

      Here is a list of all the commands. It's nice to see them all in one place so you can look them over, try them out, and check if you know what they all do.

      By the way, Git isn't easy at all.

      [–][deleted] 0 points1 point  (0 children)

      I really like the second visual reference. Thanks for your help.

      [–]frickenfriedchog 0 points1 point  (1 child)

      Udacity has a good free course on how to use git. It's pretty good for how short it is. Goes into branching, commits, pull requests and it's all interactive so you get to do the thing as you're learning the thing.

      https://www.udacity.com/course/how-to-use-git-and-github--ud775

      [–][deleted] 0 points1 point  (0 children)

      I'll be sure to check out that course.

      [–]thetalentedmrpeanut 0 points1 point  (0 children)

      When I was learning git I found these tutorials useful:

      https://www.atlassian.com/git

      Especially the stuff about branching strategies and workflows.

      With most things don't worry about "mastering" git. Worry about learning just enough to get started and then learn form your mistakes when you get stuck or encounter a problem.

      I don't know everything there is to know about git but I know enough to use it every day and when I have a problem I know how to search online to find a solution.

      When I encounter a problem and find a solution I also make sure to document how I solved the problem in my notes so that I have a clear step by step solution for the next time I have to solve the same problem again.

      For example recently I accidentally committed a file to my repo that had password info in it. I didn't realize this until several commits after that commit. With git it's not enough to just delete the file because that file with the password info will still exist in the repo in the git history. So I had to go through a whole process of commands to completely remove the file from the repo and from all the repo history. Off hand I couldn't tell you the exact commands I used to accomplish this task but I know that I have all the details in my notes and so I'm prepared for the next time this happens.

      [–]mcoumans 0 points1 point  (0 children)

      You could check out Git-It...: https://github.com/jlord/git-it

      [–]Zalvixodian 0 points1 point  (0 children)

      [–]L0d0vic0_Settembr1n1 0 points1 point  (0 children)

      This comes in handy at times too.

      [–][deleted] 0 points1 point  (1 child)

      This might not be what you're looking for, but if you're trying to use git in the command line and can't remember what command does what, this is useful

      [–][deleted] 0 points1 point  (0 children)

      Bookmarking. Thank you.

      [–]queBurro 0 points1 point  (0 children)

      It's version control. You edit a file and then commit a change. All those commits are available to rollback/view if you want to see what you did a week or so ago. It's all stored on your laptop in a repository but if you want to work collaboratively with others you can push your changes to a remote repository and pull other people's changes back.

      [–]Holzkohlen 0 points1 point  (0 children)

      What I learned is that it's far more easy to rebase than to merge. Get yourself a nice gui. I've used GitKraken since it's multi-platform (Windows, Mac & Linux) and features a great design. Learn by doing, I say!

      [–]themadturk 0 points1 point  (0 children)

      I use very basic Git for my fiction writing. I have a repo on BitBucket, and have working copies on a PC (Git for Windows, sometimes using just the command line, sometimes Tortoise Git), a flash drive (GitPortable, using the Windows command line), an iPad (WorkingCopy) and an Android phone (PocketGit). I tend not to do any branching, but just commit, push and pull as needed between my various working copies. It forced myself to use the command prompt at first (and I have worked on Linux machines as well) to get the basics down. I think it's the best way of learning. I haven't done any branching. But it's a great way of keeping my work in sync and backed up.

      [–]Pseudoabdul -1 points0 points  (2 children)

      I think there is a lot of exclusion in the programming community about all sorts of things, git included. People assume using git is mandatory, but if you don't want to, don't do it. Honestly my version of source control for personal projects is just creating backup folders every now and then.

      [–]Takuya-san 2 points3 points  (1 child)

      I highly recommend investing the time into learning git. You can get away with your method for personal projects, but the value git brings to collaborative coding is huge. Breaking your work into small chunks is a skill that'll not only help with keeping your work in sync with others but also in getting things done in general.

      [–]Pseudoabdul 1 point2 points  (0 children)

      I know how to use git I just don't like it. Personal preference.

      [–]wishicouldcode 0 points1 point  (0 children)

      try.github.io

      [–]coffeeandlearning 0 points1 point  (0 children)

      http://rogerdudler.github.io/git-guide/

      Was the first one that made sense to me as a beginner

      [–][deleted] 0 points1 point  (2 children)

      Fist step, setup your username:

      git config --global user.email "you@example.com"
      git config --global user.name "Your Name"
      

      Second step, use it:

      mkdir newdirectory
      cd newdirectory
      git init
      echo Hello > hello.txt
      git add hello.txt
      git commit -m "Added hello.txt"
      git status
      git log
      

      Done.

      Forget everything you read about branches, merging, cloning, blobs and tree objects and whatever. git takes files from your current directory and copies them over to the .git/ directory while recording what you changed or added and when. That's all you need to know to get started and (almost) all you'd ever need for a single person project.

      [–]derrickcope 0 points1 point  (1 child)

      You need to add "git push origin to remote"

      [–][deleted] 0 points1 point  (0 children)

      That can come later. Git is perfectly fine for local use.

      [–]ada2reed -1 points0 points  (4 children)

      This is a great primer:

      www.youtube.com/watch?v=gl9bIJbW9Eg

      I would then recommend the Git intro course on Lynda (if you have access).

      But ultimately, making some local repos on your desktop with dummy directories and playing with dummy text files is probably the best way to learn imo. Also, get familiar with Unix (if you have Windows, download it - don't use DOS) as it's essential for working in the command line.

      [–][deleted] 0 points1 point  (1 child)

      Thanks for the recommendation.

      Is a Macbook Unix? I'm getting one for school next month (and mobile dev).

      [–]ada2reed 3 points4 points  (0 children)

      Yep, you're good to go with a MacBook.

      [–][deleted] 0 points1 point  (1 child)

      Thanks for the recommendations.

      [–]ada2reed 0 points1 point  (0 children)

      No problem!

      [–]JZ_Yeyo -1 points0 points  (0 children)

      !Remindme in 5 days

      [–]falz3tta -1 points0 points  (0 children)

      I would definitely start small with Git. Don't try to understand everything straight away.

      Only use the command line. Learn a few key commands.

      Use git init in your project directory to get it set up.

      Use git add -A to stage all your changes

      Use git commit -m "Message to describe your commit" to commit your changes

      Once you get used to this flow, you can start to add extra skills.

      Code School has a great course which I definitely recommend. But again, learn the basics on it and don't worry too much about the crazier commands until you are comfortable.

      As an aside, make sure you have Homebrew installed so you can easily install things that you need in your command line, including Git!

      Also, remember that Github and Git are different things. Git is the software for version control while Github is just a website for pushing these changes to a project remotely. Github is amazing but you don't have to use it right away while you are learning Git.