This repository has been archived on 2023-11-08. You can view files and clone it, but cannot push or open issues or pull requests.
How-To-Git-Started/README.md

200 lines
5.3 KiB
Markdown
Raw Normal View History

2020-01-15 15:31:14 +01:00
# How to Git started
2020-01-15 15:32:03 +01:00
This is the information provided for the git workshop held at the CIT on the 29th of January 2020.
2020-01-15 15:31:14 +01:00
2020-01-09 13:50:49 +01:00
Table of Contents
=================
* [How to Git started](#how-to-git-started)
* [Using a GUI](#using-a-gui)
2020-01-09 13:54:34 +01:00
* [Learning objectives](#learning-objectives)
* [Assignments](#assignments)
* [Assignment 1: Create a repository](#assignment-1-create-a-repository)
* [Assignment 2: Your first commit](#assignment-2-your-first-commit)
* [Assignment 3: Merge conflicts](#assignment-3-merge-conflicts)
* [Assignment 5: Branching](#assignment-5-branching)
* [Assignment 6: Merge branches (Or Rebase)](#assignment-6-merge-branches-or-rebase)
* [Assignment 7: Pull requests](#assignment-7-pull-requests)
* [Assignment 8: Undo / Revert commit](#assignment-8-undo--revert-commit)
* [Assignment 9:](#assignment-9)
2020-01-09 13:50:49 +01:00
* [Using the terminal](#using-the-terminal)
2020-01-13 10:34:45 +01:00
* [Configure tooling](#configure-tooling)
2020-01-09 13:54:34 +01:00
* [Terminal commands](#terminal-commands)
2020-01-13 10:34:45 +01:00
* [Branches](#branches)
* [Glossary](#glossary)
* [Resources](#resources)
2020-01-09 13:50:49 +01:00
2020-01-08 13:52:06 +01:00
2020-01-15 13:46:33 +01:00
## Install Git
Download git for your operating system at: git-scm.com/downloads
## Using a GUI
You can use any GUI for git, the one we will be using for this workshop is Sourcetree <br/>
2020-01-15 15:39:47 +01:00
Another recommended GUI to use it Fork. <br/>
You can download these at https://www.sourcetreeapp.com/ and https://git-fork.com/
2020-01-08 16:46:22 +01:00
For other GUIs check out https://git-scm.com/downloads/guis/
2020-01-09 12:04:01 +01:00
Our remote git server is located at https://git.web.rug.nl/ <br/>
2020-01-09 13:42:43 +01:00
You can log in with your usual p-number and password.
2020-01-09 12:04:01 +01:00
2020-01-13 09:07:07 +01:00
This README has been written in markdown. <br/>
To get started see the following cheat sheet: <br/>
2020-01-13 09:07:25 +01:00
2020-01-13 09:07:07 +01:00
Cheatsheets: <br/>
2020-01-09 14:16:58 +01:00
[Markdown](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet)
2020-01-09 13:54:34 +01:00
## Learning objectives
2020-01-08 17:01:45 +01:00
- Introduction to VCS
- Create new repository
2020-01-09 14:16:58 +01:00
- README.md
2020-01-08 17:01:45 +01:00
- Git ignore file
2020-01-15 13:56:53 +01:00
- Stage
- Commit
- Push / pull
2020-01-15 13:46:33 +01:00
- Fork
2020-01-15 13:56:53 +01:00
- Pull request
- Branche
2020-01-08 17:01:45 +01:00
- Merge / Rebase
2020-01-09 16:21:27 +01:00
- Undoing Things
- Amend commits
- Unstaging
- Unmodifying a modified file
- Revert and reset
2020-01-09 10:31:59 +01:00
- Tag
- Log
2020-01-08 16:49:24 +01:00
## Using the terminal
2020-01-13 09:41:23 +01:00
### Configure tooling
2020-01-08 13:52:06 +01:00
2020-01-13 09:41:23 +01:00
Configure user information for all local repositories
2020-01-08 13:52:06 +01:00
2020-01-15 15:31:14 +01:00
```shell
2020-01-13 10:08:50 +01:00
$ git config --global user.name "[name]"
2020-01-15 13:56:53 +01:00
# Sets the name you want attached to your commit transactions
$ git config --global user.email "[email address]"
# Sets the email you want attached to your commit transactions
2020-01-13 10:08:50 +01:00
```
2020-01-08 13:52:06 +01:00
2020-01-13 10:08:50 +01:00
```shell
2020-01-15 13:56:53 +01:00
$ git config --global color.ui auto
# Enables helpful colorization of command line output
2020-01-13 10:08:50 +01:00
```
2020-01-13 09:41:23 +01:00
```shell
2020-01-15 13:56:53 +01:00
$ git config --global core.editor "nano"
# Sets the default editor to nano
2020-01-13 10:08:50 +01:00
```
2020-01-15 13:56:53 +01:00
2020-01-08 13:52:06 +01:00
If you want to save your https credentials run
2020-01-08 13:55:14 +01:00
```shell
2020-01-08 13:52:06 +01:00
git config --global credential.helper store
2020-01-08 13:54:15 +01:00
Omit --global to set the identity only in this repository.
2020-01-08 13:52:06 +01:00
```
2020-01-13 10:08:50 +01:00
2020-01-09 13:45:15 +01:00
Or you can add an [SSH key](https://help.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account)
2020-01-08 14:03:33 +01:00
2020-01-15 13:56:53 +01:00
Check your config using
```shell
$ git config --list
```
2020-01-09 13:54:34 +01:00
### Terminal commands
2020-01-09 13:14:14 +01:00
See changes that have been made
```shell
git diff
```
2020-01-08 14:03:33 +01:00
2020-01-09 13:09:47 +01:00
Adding files to commit
2020-01-09 13:09:17 +01:00
```shell
git add file1 file2
git add *
```
2020-01-09 16:51:34 +01:00
Committing files with commit message, this will stage your changes
2020-01-09 13:09:17 +01:00
```shell
git commit -m "your commit message"
```
2020-01-08 14:03:33 +01:00
unstage by using
```shell
use "git reset HEAD <file>..." to unstage
```
2020-01-08 14:52:55 +01:00
2020-01-13 09:41:23 +01:00
### Branches
Branches are an important part of working with Git.
Any commits you make will be made on the branch youre currently “checked out” to.
Use git status to see which branch that is.
Creates a new branch
2020-01-13 10:08:50 +01:00
```shell
$ git branch [branch-name]
$ git checkout -b [branch-name]
```
2020-01-13 09:41:23 +01:00
Switches to the specified branch and updates the working directory
2020-01-13 10:08:50 +01:00
```shell
$ git checkout [branch-name]
```
2020-01-13 09:41:23 +01:00
Combines the specified branchs history into the current branch. This is usually done in pull requests, but is an important Git operation.
2020-01-13 10:08:50 +01:00
```shell
$ git merge [branch]
```
2020-01-13 09:41:23 +01:00
Deletes the specified branch
2020-01-13 10:08:50 +01:00
```shell
$ git branch -d [branch-name]
```
2020-01-09 13:12:45 +01:00
2020-01-13 10:08:50 +01:00
Show all available branches
2020-01-09 13:12:45 +01:00
```shell
git branch -a
```
2020-01-08 14:52:55 +01:00
Track remote branch
```shell
git checkout --track origin/<branch>
```
Delete remote branch
```shell
git push <remote_name> --delete <branch_name>
git remote prune <remote_name>
```
2020-01-13 10:08:50 +01:00
2020-01-09 12:53:06 +01:00
Check the log in graph form
```shell
git log --graph --oneline
```
2020-01-13 10:11:06 +01:00
## Glossary
- git: an open source, distributed version-control system
- GitHub: a platform for hosting and collaborating on Git repositories
- commit: a Git object, a snapshot of your entire repository compressed into a SHA
- branch: a lightweight movable pointer to a commit
- clone: a local version of a repository, including all commits and branches
- remote: a common repository on GitHub that all team members use to exchange their changes
- fork: a copy of a repository on GitHub owned by a different user
- pull request: a place to compare and discuss the differences introduced on a branch with reviews, comments, integrated tests, and more
- HEAD: representing your current working directory, the HEAD pointer can be moved to different branches, tags, or commits when using git checkout
2020-01-13 10:34:45 +01:00
## Resources
2020-01-13 10:35:20 +01:00
https://gitexplorer.com/ <br/>
https://git-school.github.io/visualizing-git/ <br/>
https://education.github.com/git-cheat-sheet-education.pdf <br/>
https://gitsheet.wtf/ <br/>
https://www.keycdn.com/blog/git-cheat-sheet <br/>
2020-01-13 10:34:45 +01:00