Intro to Git and GitHuB

Git

  • Git is a version control system widely used in open source software
    • Created by Linus Torvalds in 2005
  • Is a distributed VCS
    • Everyone has a full copy of the repository, including history
  • Git is pre-installed on most Linux systems, including GL

GitHub

  • Even though Git is distributed, the files still need to be shared between collaborators
  • Any publicly accessible web server could serve this purpose but
    • GitHub adds lot of nice features on top, including a nice web interface to view code in
  • GitHub is not the only git host, but is by far the largest
    • BitBucket is another popular one, gives unlimited free repositories

Getting a Git repo

  • If you are starting out with a new code base, simply
    • create a folder for your project
    • run git init inside the folder to make a git repository
  • If you want to use existing code, say from GitHub, you can use the git clone command
In [2]:
%%bash
git clone https://github.com/bwilk7/CMSC433
Cloning into 'CMSC433'...

Git on GL

  • Git on GL is outdated, so you need to include your GitHub username in the URL for the git clone command
  • It also prompts for a password using a window, fix this by running
    • unset SSH_ASKPASS on bash shells
    • unsetenv SSH_ASKPASS c-shells
In [ ]:
%%bash
git clone https://bwilk7@github.com/bwilk7/433Fall17/

Adding Changes to Git

  • After modifying some of your code, it is a good idea to add the changes to the repository
  • The command git add FILE adds a new version specific file to the repository
    • You can used wildcard to add many files at once, just be careful

Commiting Changes

  • After adding the files, the changes needed to be commited to repository

    • This calculates the difference between existing files and the ones youv'e added, as well as marks a specific point with a message
  • To commit the added files in your Git repository use the command git commit -m MESSAGE where MESSAGE is some informative information about the change you made

Pushing the Code

  • If you want to push your code back to GitHub, that is make the repository on GitHub match your local repository, use the command git push <remote> <branch>
  • If you cloned your code from GitHub, then GitHub will be set as the origin, so your command might be
git push origin master
  • You can have multiple remote points, and multiple branches, but for this course, they shouldn't be needed

Working Across Computers

  • If you want to work on the same code across multile computers, thats fine!
  • First clone the repository to the computers to want to work on
  • After committing some changes and pushing them back to GitHub on computer A, you need to update computer B's repository
    • This is accomplished using the command git pull origin

Merges

  • Git does it best to merge files together when multiple people have made changes on them
  • Sometimes it is hard to figure out how to merge, and it will leave conflicts in your code
  • To fix a conflict, edit the conflicted files, and add them again using git add
    • I don't expect conflicts to be an issue in this class