Intro to Git & GitLab

Code4libBC edition

Git Logo

Cynthia Ng | @TheRealArty
November 30, 2018

Thanks

Git Logo

@svesselov

What is Git?

Git is a version Control system for tracking changes in computer files

Why do we need it?

Benefits of Git

Accessible

Everyone can contribute!

Distributed

Enable large and distributed teams to collaborate

History

Every change is tracked

Git & GitLab

Git ≠ GitLab

GitLab

  • GitLab is open source, users can host Git repositories publicly and privately for free.
  • GitLab has one vision. Everyone can contribute to all digital content.
  • Open source projects host or mirror their repositories on GitLab.
  • Post your own code for others to use or contribute to.
  • Use and learn from the code in other people's repositories.

GitLab's Awesome Features

  • Unlimited private projects and collaborators.
  • Built-in CI/CD
  • Preview your changes with Review Apps
  • Publish static websites for free with GitLab Pages
  • Public projects and groups get all gold plan features for free

Git Terms

The Lingo!

Repository

Place where files are stored and managed

Server

The computer that stores your repository

Client

The computer you use to connect to the server

Local Copy

Repository files you keep on your computer to make changes

Server Repo Illustration

More Lingo!

Branch

One version of the code

Master

The primary version of the code for the repository

Merge

Add changes from one branch into another

Fork

A copy of the repository

Branching Illustration

Setup Account with GitLab

GitLab Sign-in
https://gitlab.com

First look at GitLab

Welcome to GitLab

GitLab Projects

WWC Git Project

GitLab Groups

WWC Gitlab Group

Let's do it!

Our First Merge Request

Merge Request
Fill in the details
Merge Request
Merge your Merge Request
Merge Request
See your Changes
Merge Request Changes
Success!
Merge Confirmation

Making changes using Git!

Read: Using the Command Line (cli)

Check your computer for Git
						
							$ git --version
						
					
** No need to type in the $, this just indicates it is a shell command.
Output
								
									git version 2.18.0
								
							
Download Git Download Git: https://git-scm.com/downloads
Check for a default name Git will use when you commit
							
								$ git config --list
							
						
Set the default name Git will use when you commit
							
								$ git config --global user.name "First Name Last Name"
							
						
Set the default email Git will use when you commit
							
								$ git config --global user.email "email@example.com"
							
						
** The quotes are necessary! They indicate that the words inside the quotes are a string and not a command.
View your config settings
						
							$ git config --list
						
					
Output
								
									user.name=your.name
									user.email=email@domain.ca
								
							

Visual Studio Code

Load your choice of directory.
							
								File -> Open
							
						

Clone

Copy the repository with Git
							
								$ git clone https://gitlab.com/code4lib/bc/2018-fun-times.git
							
						
Move into the repository directory
							
								$ cd 2018-fun-times
							
						

Double check your location.

Windows:
						
							$ dir
						
					
Other:
						
							$ ls
						
					
Let's check the status of our Git Repo.
						
							$ git status
						
					
Create a new branch & checkout
						
							$ git checkout -b BRANCHNAME
						
					

Make a change

Open up your file and edit it.

Check git status
								
									$ git status
								
							
Output
								
									modified: filename.md
								
							
Stage file for tracking
								
									$ git add filename.md
									OR
									$ git add .
								
							
Check status
								
									$ git status
								
							
Output
								
									modified: filename.md
								
							
Time to commit!
								
									$ git commit -m "details of the change made"
								
							
Check status
								
									$ git status
								
							
Output
								
									On branch [BRANCHNAME]
									nothing to commit, working tree clean
								
							
Push & Set Origin
							
								$ git push origin BRANCHNAME
							
						
Output
								
								To gitlab.com:code4lib/bc/2018-fun-times.git
								* [new branch]      BRANCHNAME -> BRANCHNAME
								
							

Phew! That was a lot. Let's review!

Review

config

Get and set global or repo options

status

Show the working tree status

checkout

Switch branches and can create new branch

add

Adds the file contents to the index, and stages

commit

Add the changes from one file to another, bringing them up-to-date

push

Send the changes to the server

Checkout Master
							
								$ git checkout master
							
						
Sync with Master
								
									$ git pull origin master
								
							
Check Status
								
									$ git status