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 13:46:33 +01:00
|
|
|
|
## Install Git
|
2020-01-16 11:24:29 +01:00
|
|
|
|
Download git for your operating system at: https://git-scm.com/downloads
|
2020-01-15 13:46:33 +01:00
|
|
|
|
|
2020-01-16 11:24:29 +01:00
|
|
|
|
You can use any GUI for git but to get a deep understanding of git we will use the terminal.
|
|
|
|
|
For available GUIs check out https://git-scm.com/downloads/guis/
|
2020-01-08 16:32:58 +01:00
|
|
|
|
|
2020-01-16 11:24:29 +01:00
|
|
|
|
Our remote git server is located at https://git.web.rug.nl/
|
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-16 11:24:29 +01:00
|
|
|
|
This README has been written in markdown.
|
|
|
|
|
To get started see the following cheat sheet:
|
2020-01-13 09:07:25 +01:00
|
|
|
|
|
2020-01-16 11:24:29 +01:00
|
|
|
|
Cheatsheets:
|
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-16 12:03:21 +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
|
|
|
|
- Log
|
2020-01-16 11:31:42 +01:00
|
|
|
|
- Tag
|
2020-01-08 16:25:16 +01:00
|
|
|
|
|
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 you’re 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 branch’s 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-16 11:24:29 +01:00
|
|
|
|
https://gitexplorer.com/
|
|
|
|
|
https://git-school.github.io/visualizing-git/
|
|
|
|
|
https://education.github.com/git-cheat-sheet-education.pdf
|
|
|
|
|
https://gitsheet.wtf/
|
|
|
|
|
https://www.keycdn.com/blog/git-cheat-sheet
|
2020-01-13 10:34:45 +01:00
|
|
|
|
|