A minimalistic Git intro for mr Norfolker


  • Patron

    Git is primarily a way to keep a history of file changes for a project. The technical term for this is version control. You interface with Git using a GUI or a shell/terminal. This guide assumes the latter. Here’s a simple workflow:

    • By executing the command git init you’re saying “this folder contains a project that I want to track with git”. This folder now becomes what’s called a Git repository.
    • git add . says “add all files in the folder to git”, which makes Git track their changes. Files in a folder are not added automatically when you do git init, or if you create a file in a folder that already is a Git repository.
    • git commit -am "my new feature" makes an entry in the Git history for this repository. This means you can later revert to this point in history, should you shoot yourself in the foot.
    • Doing git status will show you what current uncommitted changes are in the git repo, and also if there are any untracked files.
    • By default a Git repo contains a single branch called “master”. You can create another branch named for example “experimental” by doing git branch experimental. This branch is now a copy of “master”. You can switch to that branch by doing git checkout experimental. The main point of this is to isolate work on a specific feature, which might or might not turn out to be a good idea. Switching between branches will change all files in the git repo to the version in the branch you’re switching to.
    • After working in the experimental branch, committing changes and finishing what your doing, it is customary to merge these changes back into the master branch. This is as easy as doing git checkout master to switch back to master, and then git merge experimental to copy the changes from experimental over to master.

    Git is also a powerful collaboration tool, due to the fact that you can keep remote copies of the same repository in sync:

    • By doing git remote add philipsmess git@some.url I’m adding a connection called “philipsmess”, which is assumed to be a copy of the same repo I’m having.
    • Now I can do git pull philipsmess master to fetch the changes from the master branch in your repo…
    • …or git push philipsmess master to push my changes up to you.

    As Git is super clever about merging your changes without overwriting mine, this is mostly a completely pain-free process, unless we have both edited the same place in the same file. That results in a merge conflict, which calls for a human brain to decide which version should take precedence.

    Now, Github is just another computer running Git, and commonly used as a source of truth (and an online safehouse in case your and my machine both blow up). So you and I would both push/pull to/from the Github version of the repo, and never communicate directly with each other.

    Forking is a Github term, meaning simply to create a clone (which is a Git term) of a repository. After having done that you can create a pull request, another Github term, which knocks on the door of the owner of the original repo, asking him if he wants to merge your changes into his repo.

    Was that any clearer, @cheersphilip, or did I just add to your confusion? :)


  • Patron

    I can also recommend the Bootcamp on the Github site, which is a tiny but very concise guide without cruft or assumptions of prior knowledge.


  • Tiger Hat

    Dammit, I guess i have no excuse now, do I?!

    Imma fork me a repo!

    Thanks @David for taking the time to spell it out for me :)

    I am probably very slow, as it’s still not crystal clear to me… is Git a program on my computer? Where would I find that? Or should I not bother and just use Github?


  • Tiger Hat

    Okay, here’s an even more dumb question! Why do you even need formal version control… I mean, what’s wrong with just saving a copy of your files every so often and moving on…


  • Patron

    Git is installed locally on your computer, yes. The only time you can use just Github is if you don’t need the code on your local machine, and are happy doing the editing online using their simple editing stuff.

    Typically to do a very very simple change to someone else’s repo that isn’t already on your local machine.


  • Patron

    Okay, here’s an even more dumb question! Why do you even need formal version control… I mean, what’s wrong with just saving a copy of your files every so often and moving on…

    It’s the same thing! The point of Git is that it does this for you, continuously, in the background.

    So the point of a formal version control is that it’ll never forget to do the copy. While you most definitely will.


  • Tiger Hat

    Wow, okay that seems pretty useful, although of course i never forget anything :P


  • Tiger Hat

    Okay, now I’m feeling really dumb…

    I can’t get git init to work - i have tried Windows PowerShell and Command Prompt, and neither will accept the command ‘git’.

    Is perhaps because I’m on a networked/firewalled work computer? I’ve no experience with command-line stuff - I had to Google how to change directory and everything :(


  • Patron

    Are you sure Git is actually installed? It’s not a command that’s available natively in the terminal, the program has to be downloaded and installed first.

    Then you probably have to do some magic to make the git command globally recognizable. On a Mac/Linux that entails adding it to your “path”. On a Windows machine, god knows. :)


  • Tiger Hat

    Crikey… I will do more research , so as to not take up any more of your time

    Thanks for all your help!



  • Crikey… I will do more research , so as to not take up any more of your time

    Thanks for all your help!

    That second link of yours looks like it’s on the money @cheersphilip, it refers to a “Github for Windows” that’ll install it’s own shell, that way Git will be on your programs list in Windows, you open it and it should open it’s own command prompt, then all of @David’s commands should workout.

    One thing that should hammer home the understanding of Git would be a podcast, you see Linus Torvalds (the creator of the Linux Kernel) created Git when other version control systems didn’t do the job, someone’s bound to have interviewed him on it. I remember FLOSS Weekly interviewed him at a hotel a few years ago but that may be too general, FLOSS Weekly did however interview the Git maintainer who took over http://twit.tv/floss19

    Listen to that when you get a chance it should cover what you’re looking for.


  • Tiger Hat

    I’m up and running!

    I listened to @Affordable_Desk’s podcast, I followed @David’s instructions - I have set up my computer with Git! As an added bonus I have also followed @geoffb by installing Github for Mac.

    Imagine my surprise when I found that I already have a couple of repos on Github, that are now on my computer!

    So, I started a new repo on my macbook and that, when I get time to actually write some code, will be the basis of the second version of my plate-spinning game :)

    It’s all starting to come together in my brain - I had repos on Github, as I needed a solution for working on different computers, but now I can see how it will help me with version control - sweet!

    Thanks guys for all your help!



  • I listened to @Affordable_Desk’s podcast

    I have a podcast?? I knew I did something every week on Wednesdays when I black out for two hours in the evening that must be it, well join me next week on Deskcast when I’ll be interviewing Matt Hackett and Horseblair on the lack of Trains in today’s games and what their studio (Lost Decade Games) intend to do about it!!

    And remember guys, Affordable_Desk gets Affordable_Guests.


  • Patron

    I’m up and running!

    Hey, that’s great! Well done, @cheersphilip!

    Be sure to report back on your experience of it all - do you actually use it in your workflow and find it helpful, or did you find it to be overkill and that you were just as well off before?


  • Tiger Hat

    So now I initiate repos from the terminal, then go to Github, which tells me to do these two commands:
    git remote add origin https://github.com/cheersphilip/website-2014.git
    git push -u origin master

    And that’s pretty much it! I’m pretty happy about how this is working out :)
    As I said before, all I need to do now is find the time to actually write some code!
    :D

    EDIT - I’d like to make it clear that I don’t understand what push -u origin master means exactly, but I’m happy that it works, so…


  • Tiger Hat

    @geoffb can this get moved to gamedev as well? I found it super useful :)


  • LDG

    @cheersphilip said:

    @geoffb can this get moved to gamedev as well? I found it super useful :)

    Done!


Log in to reply