Getting Started with GIT

Reviewed by bil hays, 2019.05.06

If you haven’t started using a software repository system, you might find the following useful. Repos like cvs, svn, and git allow for version control, restoration of snapshots, and facilitate multiple people working on a project without getting in each others way. We recommend git, but some of you alluded to past bad experiences with git. git doesn’t work well with large datasets (it is for source code) and it can be complex and frustrating, especially when the remote and local repos differ. I’ve heard also that it doesn’t play well with the Unity game development platform. So it’s not the tool for every problem, and we support svn and cvs if you’re rather use one of those.

Mike Reiter sent me this link, which is a pretty wonderful rant about git. The comments are also very good:
https://reprog.wordpress.com/2010/05/12/still-hatin-on-git-now-with-added-actual-reasons/

And for data, something I just stumbled upon is the data project. It’s in beta and looks interesting:
http://datproject.readthedocs.org/en/latest/

Also, we have a server supporting this software, information on that service is in the link below. Use of this service is highly recommended, your repos will be backed up, and since this is not part of your afs home directory, it eases transition for your software after you graduate or otherwise move on.

These links may help you get started:
https://cs.unc.edu/help-article/cvs-repositories/
http://www.sitepoint.com/introduction-to-git-1/
https://training.linuxfoundation.org/free-linux-training/linux-training-videos/introduction-to-git
https://git-scm.com/book/en/v2/Getting-Started-Git-Basics

You will need to make a public/private key pair for access to the cs git repositories. If you have a public/private keypair already, send help@cs.unc.edu the public key (not the private key) and we’ll get you set up.

Very Important: We use AFS home directories on our linux servers. For that reason, the way you set up keys is different on our server than what you would do on your personal machine or a login server that used local accounts. See section B for setting up keys on your personal computer.

A) How to set up ssh key on CS login servers

See  https://cs.unc.edu/help-article/ssh-keys/ ‎for more detail on this topic.

Use a SSH to login to the classroom.cs.unc.edu or login.cs.unc.edu linux server. You’ll make a directory that only you can access in your afs home directory, since AFS has to be able to read your .ssh folder. You don’t want to use .ssh for private keys. Run these commands:

mkdir .ssh-private
fs sa .ssh-private system:administrators none
fs sa .ssh-private system:anyuser none

then run
fs la  .ssh-private

And see that only you have permissions to use that directory. This is not an issue on your personal machines, on cs.unc.edu OS X boxen, or on cs.unc.edu windows machines, since we don’t use AFS home directories on these systems, but you need to do this on the CS login servers.

Create the key pair thusly:

/usr/bin/ssh-keygen -t rsa -N ” -b 4096 -C ‘<Put your CS userid here>@cs.unc.edu’ -f ~/.ssh-private/<Put your CS userid here>@cs.unc.edu.rsa

comment (-C) should be your email address. Note the “-N ””, the two single quotes with nothing between them creates a key without a passphrase. Send a copy of the key that ends in .pub to help@cs.unc.edu and we’ll install it on the git server.

It’s very important that you keep close guard of the private key. If you want to use the same private key on your personal machines make sure to use a secure method such as sftp to copy it.

If you’re using mac/linux, when you login and want to use git, you would add your private key to an ssh-agent using something like this:
eval $(ssh-agent)
ssh-add /Users/hays/.ssh-private/hays@cs.unc.edu.rsa

You can verify that the key is loaded with
ssh-add -l

B) How to set up ssh key on stand alone servers and workstations.

Windows users have a couple of options. One is to use the Putty tools to create public/private key pairs, there is a good tutorial here:
https://confluence.atlassian.com/sourcetreekb/generate-and-load-ssh-keys-into-sourcetree-with-putty-790629663.html

Another option is Git for windows, which leverages a bash shell on windows. In this, you can use the mintty terminal emulator to create a .ssh folder and ssh keys just as one would on a linux system, and use git on the command line. It has a GUI git client, but it’s pretty sparse, so we don’t recommend it. But it’s an excellent tool for command line use. If you have bash on windows, you can generate keys just like you would on linux or a mac.

Creating Keys from bash or similar shells

First, see if you already have a .ssh dir in your home:

ls -la ~/.ssh

Create the key pair thusly:

/usr/bin/ssh-keygen -t rsa -N ” -b 4096 -C ‘<your email address>’ -f ~/.ssh/<your email address.rsa>

comment (-C) should be your email address. Note the “-N ””, the two single quotes with nothing between them creates a key without a passphrase. Send a copy of the key that ends in .pub to help@cs.unc.edu and we’ll install it on the git server.

It’s very important that you keep close guard of the private key. If you want to use the same private key on your personal machines make sure to use a secure method such as sftp to copy it.

If you’re using mac/linux, when you login and want to use git, you would add your private key to an ssh-agent using something like this:
eval $(ssh-agent)
ssh-add /Users/hays/.ssh/hays@cs.unc.edu.rsa

You can verify that the key is loaded with
ssh-add -l

GUI Git client Sourcetree and PuTTY tools

Sourcetree is a good choice of git client, they offer a windows and mac version and integrates with bitbucket and github. To use Sourcetree on our git service, you need to connect using a key. PuTTY is a free collection of packages that support interaction between windows workstations and linux servers. putty-gen.exe can used to make public private key pairs or to convert an ssh key to a windows native .ppk key. PuTTY also includes pagent.exe, which is key agent similar to ssh-agent. The short version is you go to the putty project and download putty-gen and pageant (get putty and psftp also, they are very useful). Then:

-Copy your private key to the windows machine in a safe place, or use the putty-gen.exe to make a key if you don’t have one already.
-Save it with a .ppk extension
-Use putty-gen to convert to a key putty can use
-Use pageant to load the key into the system

More detail on this can be found here:
https://benjaminhorn.io/code/sourcetree-for-windows-ssh-keys/