|
|
# Git - Version Control
|
|
|
Git is a [distributed version-control system](https://en.wikipedia.org/wiki/Distributed_version_control) for tracking changes in your code. It also makes it possible to revert changes in case of any mistakes.
|
|
|
|
|
|
Gitlab uses Git to track your code and is a remote place for you to share and store your work. Which is great because all your work is backed up and you don't need to send in any zip-files of your assignments.
|
|
|
|
|
|
Do you want to know more? Take a look at [this book](https://git-scm.com/book/en/v2) or [here](https://www.atlassian.com/git/tutorials/what-is-git).
|
|
|
|
|
|
Down below are instructions on how to set up Git on your computer and how to get started with Gitlab.
|
|
|
|
|
|
## Step 1: Install Git
|
|
|
Download and install the latest version of Git from [https://git-scm.com/downloads](https://git-scm.com/downloads). You can find further information at [Getting started - installing Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git#_installing_on_macos)
|
|
|
|
|
|
## Step 2: Open a terminal window
|
|
|
Select your operating system.
|
|
|
|
|
|
<details>
|
|
|
<summary>Windows</summary>
|
|
|
|
|
|
These instructions are given using Bash, luckily Bash gets installed with Git. Search for, and open _Git Bash_.
|
|
|
|
|
|

|
|
|
</details>
|
|
|
|
|
|
<details>
|
|
|
<summary>macOS</summary>
|
|
|
|
|
|
These instructions are given using Bash, luckily it is the default in macOS. To open a _Terminal_ using Spotlight press `⌘ + space` and search for `terminal`.
|
|
|
|
|
|
Can't find it? Take a look at [How to Get to the Command Line on a Mac](https://www.wikihow.com/Get-to-the-Command-Line-on-a-Mac).
|
|
|
|
|
|
Recommended reading: [How to use Terminal on Mac](https://www.macworld.co.uk/how-to/mac-software/how-use-terminal-on-mac-3608274/).
|
|
|
</details>
|
|
|
|
|
|
<details>
|
|
|
<summary>Linux</summary>
|
|
|
|
|
|
These instructions are given using Bash, luckily it is already pre-installed. Search for, and open `terminal`.
|
|
|
|
|
|
Can't find it? Take a look at [How to Open a Terminal Window in Ubuntu](https://www.wikihow.com/Open-a-Terminal-Window-in-Ubuntu).
|
|
|
</details>
|
|
|
|
|
|
## Step 3: Check your Git version
|
|
|
To check your Git version run the command `git --version` in your Terminal.
|
|
|
|
|
|
```bash
|
|
|
git --version
|
|
|
```
|
|
|
|
|
|
Depending on your Git version the output should look something like this:
|
|
|
|
|
|
```bash
|
|
|
git version 2.21.0
|
|
|
```
|
|
|
|
|
|
## Step 4: Show configurations
|
|
|
List your current Git configuration using the command `git config --list`:
|
|
|
|
|
|
```bash
|
|
|
git config --list
|
|
|
```
|
|
|
|
|
|
If the output is a list of configurations it means that everything is working as expected and you can continue.
|
|
|
|
|
|
Example output:
|
|
|
|
|
|
```bash
|
|
|
core.symlinks=true
|
|
|
core.autocrlf=true
|
|
|
core.fscache=true
|
|
|
color.diff=auto
|
|
|
color.status=auto
|
|
|
color.branch=auto
|
|
|
color.interactive=true
|
|
|
help.format=html
|
|
|
diff.astextplain.textconv=astextplain
|
|
|
rebase.autosquash=true
|
|
|
http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
|
|
|
diff.astextplain.textconv=astextplain
|
|
|
filter.lfs.clean=git-lfs clean -- %f
|
|
|
filter.lfs.smudge=git-lfs smudge -- %f
|
|
|
filter.lfs.required=true
|
|
|
filter.lfs.process=git-lfs filter-process
|
|
|
```
|
|
|
|
|
|
## Step 5: Add your name
|
|
|
Add the name you want to be connected to your changes.
|
|
|
```bash
|
|
|
git config --global user.name 'Your Name'
|
|
|
```
|
|
|
:warning: _Replace `Your Name` with your actual name._
|
|
|
|
|
|
You can read more about this at [Setting your username in Git](https://help.github.com/en/github/using-git/setting-your-username-in-git).
|
|
|
|
|
|
## Step 6: Verify the name change
|
|
|
You should get your name as output when you run:
|
|
|
```bash
|
|
|
git config --global user.name
|
|
|
```
|
|
|
|
|
|
## Step 7: Add you email
|
|
|
It is **important** that you add your _student email_.
|
|
|
```bash
|
|
|
git config --global user.email 'st123id@student.lnu.se'
|
|
|
```
|
|
|
:warning: _Replace `st123id` with your student id._
|
|
|
|
|
|
You can read more about this at [Setting your email in Git](https://help.github.com/en/github/setting-up-and-managing-your-github-user-account/setting-your-commit-email-address).
|
|
|
|
|
|
## Step 8: Verify the email change
|
|
|
You should get your email as output when you run:
|
|
|
```bash
|
|
|
git config --global user.email
|
|
|
```
|
|
|
|
|
|
## Step 9: Add alias for gitignore.io
|
|
|
Usually, there are somethings that you don't want to be tracked by Git. It might be files from your operating system, node modules or secrets like passwords or access tokens. The way to inform Git about which files that should be ignored you have to create a `.gitignore` file. Perhaps the easiest way is to use [gitignore.io](https://www.gitignore.io/).
|
|
|
|
|
|
To make it even easier you should create an alias (shortcut) for using it.
|
|
|
|
|
|
```bash
|
|
|
git config --global alias.ignore '!gi() { curl -L -s https://www.gitignore.io/api/$@ ;}; gi'
|
|
|
```
|
|
|
|
|
|
## Step 10: Verify that the alias has been added
|
|
|
```bash
|
|
|
git config --get-regexp ^alias\.ignore
|
|
|
```
|
|
|
Expected result:
|
|
|
```bash
|
|
|
alias.ignore !gi() { curl -L -s https://www.gitignore.io/api/$@ ;}; gi
|
|
|
```
|
|
|
|
|
|
## Step 11: Make sure the alias works
|
|
|
Run:
|
|
|
```bash
|
|
|
git ignore
|
|
|
```
|
|
|
Expected result:
|
|
|
```bash
|
|
|
gitignore.io help:
|
|
|
list - lists the operating systems, programming languages and IDE input types
|
|
|
:types: - creates .gitignore files for types of operating systems, programming languages or IDEs
|
|
|
```
|
|
|
|
|
|
## Step 12: Add SSH
|
|
|
First time you're going to start with an exercise or assignment you will see this banner at the top of the project page. Click on the "add an SSH key" link and follow the steps.
|
|
|

|
|
|
|
|
|
Here is some information about [SSH & Gitlab](https://gitlab.lnu.se/help/ssh/README#gitlab-and-ssh-keys).
|
|
|
|
|
|
## Step 13: All done!
|
|
|
You're now done to use Git and Gitlab. If you're new to Git please take a look at the following resources to make your life easier.
|
|
|
|
|
|
- [Videos](https://git-scm.com/videos) - a couple of short videos that introduce you to the basics of Git.
|
|
|
- [Pro Git](https://git-scm.com/book/en/v2) - free online book.
|
|
|
- [Learn Git in 15 minutes](https://www.youtube.com/watch?v=USjZcfj8yxE) - an informative video by Colt Steele.
|
|
|
- [Reference manual](https://git-scm.com/docs) |
|
|
\ No newline at end of file |