Git and GitHub

Try Git

Here is a helpful three-part tutorial:

  1. Read About Version Control & the excellent Intro to Git
  2. Install Git for the command line. See the information below.
  3. Do the Try Git interactive tutorial. It basically runs you through using Git on the command line and with Github.

This information below contains recommended resources for learning Git and Github, which we will use this semester to store, manage and share our projects.

setuptocat1

GitHub is a web-based hosting service for software development projects that use the Git revision control system. GitHub offers free accounts for open source projects. As of May 2011, GitHub was the most popular open source code repository site. The site provides social networking functionality such as feeds, followers and the network graph to display how developers work on their versions of a repository. [Wikipedia]

Installing Git

Mac OSX

  • Git can be installed in Xcode via installing the Command Line Tools at Preferences->Downloads->Components
  • You can also install Git via the download from the git website or through package management tools such as Homebrew and Macports

Windows

  • Install Git for Windows which includes a Unix-like Bash terminal environment that matches the commands in the Try Git tutorial.
  • If you’re familiar with the Win/DOS Command shell but are new to Bash, check out this DOS – Bash command comparison

Linux

  • Install git through your distro’s package management system

Configure Git

  • Set you username and email address (only need to do this once).
  • $ git config --global user.name "YOUR_FULL_NAME"
    $ git config --global user.email "YOUR_EMAIL_ADDRESS"
  • Turn on git colors with makes reading status and diffs much easier (only need to do this once). You shouldn’t need to do this if you’re using the Git Bash installed by Git for Windows.
  • $ git config --global color.ui true

Useful Command Line Commands

The following are pulled form the excellent Introduction to Git. Bash/Shell A small list of the bread and butter Bash/Shell/Terminal commands. Some of these commands  respond to the”-h” or  “–help” options which print out a small usage reference. Many of the simple commands (ls, cp, mv) don’t respond to “–help” but will simply print out a usage line when they don’t understand the given arguments.

$ ls --help

Also, most have manual pages which can be reached by using the “man” command and then the program name. Here’s how to open the manual page for ls:

$ man ls

Use the UP & DOWN arrow keys to scroll and ‘q’ to quit.

  • ls – list contents of the current dir
  • cd – change directory; ~/ refers to your home dir, . refers to the current dir, ../ refers to one directory up, ../../ refers to 2 dirs up, etc
  • pwd – prints full path to the current dir (where we are)
  • mkdir – make a new dir
  • touch – create an empty file or update the timestamp on an existing file
  • mv – move a file or dir
  • cp – copy a file or folder; the -R option copies files & folders recursively (need to copy the entire contents of a given folder if it als contains folders)

Git This is just a small list of git commands. See the references below for more detailed info. All of the git commands respond to “–help”.

  • git init – initialize a dir for git source control management
  • git clone – clone a git repository from another location (another git controlled folder, somewhere online, GIthub, etc)
  • git checkout – switch to a branch, commit, or tag; the base location is the master branch
  • git status – print status of the staging area (modified files, current branch, etc)
  • git add – add a file or folder to the staging area, responds to wildcards like *.txt and . which refers to all modified files (careful with this one!)
  • git rm – remove a file or folder form the staging area, removing a modfied file may require the -f argument to force it, -r adds files recursively (useful within folders).  
  • git mv – move or rename files or folders, only works for files currently managed by git (aka added previously)
  • git commit -m “some message” – commit the current staging area (adds, modifications, removals); the -m option specifies the log message
  • git branch some_branch – creates a branch called “some_branch”; don;t forget to switch to it using git checkout!
  • git merge some_branch – merge a branch into the current branch, in this case merge “some_branch” with “master”

References

Books & Tutorials

Client Apps:

Videos:

Web Sites/Pages:

Cheat Sheets: