Setting up Git and GitLab_ CSE252 A

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Setting up Git and GitLab

What is Git and why do we use it


Git is a version control system which tracks and provides control over changes to our code. You
will use GitLab in this course to get starting files as well as submitting assignments.

There are a several reasons why we introduce version control in this course, even though it is
usually reserved for complex projects or professional practice:

I often get questions related to breakages in a previously working program. If I can see the
history of the change you made, I can quickly find the culprit.

When submitting to GitLab, GitLab can kick off tests checking for common errors or test that
you've met the requirements of the assignment.

It is an easy way to distribute starting files without having to download single files at a time or
use zip files

On group projects, I've found that students have difficulty sharing code and the codebase
quickly gets of sync between the group members. By having a central repository for the code,
it is easier to keep group projects in sync.

Install Git

MacOS
Step 1 - Install Homebrew

Open a Terminal (Applications, Utilities, Terminal)

Copy and paste the following into the terminal window and hit return

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

You will be offered to install the Command Line Developer Tools from Apple. Confirm by
clicking Install. After the installation finished, continue
installing Homebrew by hitting Return again.

Step 2 - Install Git

Copy and paste the following into the terminal window and press Return or Enter.

brew install git

Windows
Download and install git for Windows (https://git-scm.com/downloads) . Once installed, you
will launch the Git Bash program to continue the instructions.

Generate an SSH Key and Add it to GitLab


SSH keys will allow you to push and pull files from GitLab without having to type your password
each time. You will need to generate a new SSH key for each computer you use and add the
public key to GitLab.

In a Terminal (MacOS) or Git Bash (Windows), type the following:

ssh-keygen

When asked to enter a file name in which to save the key just press Return or Enter.

When asked to enter a passphrase, enter a passphrase (note that you will not see your
password/asterisks echo to the screen). This is used to encrypt your private key. Remember it,
as if you forget it, you will have to generate a new key.

Your result will look similar to this, but not exactly:

Now, you need to upload your public key to GitLab. First, get the key into your clipboard by typing:

MacOS (in Terminal):

cat ~/.ssh/id_rsa.pub | pbcopy

Windows (in Git Bash):

cat ~/.ssh/id_rsa.pub | clip


Login to the GitLab instance at git.cse252.spikeshroud.com
(https://git.cse252.spikeshroud.com) , (get your CSE252 username and password at
cse252.spikeshroud.com/cse252 (https://cse252.spikeshroud.com/cse252) ). In the (1) avatar
dropdown menu in the top right of the screen, choose (2) Settings. On the Settings page, click (3)
SSH Keys. (4) Paste in your key, give it a title if it doesn't get one automatically, and click Add key.

Run the SSH Agent


Now, if you were to start using Git right away, you would be continually prompted for the
passphrase that you used to encrypt your private key, in essence replacing the need for a GitLab
password with a SSH key password.

In a Terminal (MacOS) or Git Bash (Windows), copy/paste the following (note that if you type it,
those are backticks `, not single quotes ' ):

eval `ssh-agent` && ssh-add

You will be prompted to enter your key's passphrase.

Interacting with Git and GitLab


Before you start running git commands, you'll need to configure your local environment.

Run the following commands in Terminal (MacOS) or Git Bash (Windows)

1. git config --global user.name "YOUR NAME" , replacing YOUR NAME with your name
2. git config --global user.email [email protected] , replacing [email protected] with your e-
mail address.
3. git config --global push.default simple

Setting Core Editor


It is important to set your core.editor configuration, as the default uses a text editor called vi that
can be difficult for new users to use.

First, make sure you can run VS Code from the command line:

code --help

You should get some output about the Visual Studio Code version. If that doesn't work and you
are using MacOS, then in VS Code, do View, Command Palette and select "Shell Command:
Install 'Code' command in path".

Once code can be launched from the command line, configure git to use it with this command:

git config --global core.editor "code --wait --new-window"

You might also like