Intro to Git & GitLab
Code4libBC edition
Cynthia Ng | @TheRealArty
November 30, 2018
Thanks
@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
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 |
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 |
Setup Account with GitLab
https://gitlab.com
First look at GitLab
GitLab Projects
GitLab Groups
Let's do it!
Our First Merge Request
Fill in the details
Merge your Merge Request
See your Changes
Success!
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.
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
Stage file for tracking
$ git add filename.md
OR
$ git add .
Time to commit!
$ git commit -m "details of the change made"
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
|
Get and set global or repo options |
|
Show the working tree status |
|
Switch branches and can create new branch |
|
Adds the file contents to the index, and stages |
|
Add the changes from one file to another, bringing them up-to-date |
|
Send the changes to the server |
Checkout Master