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

221 lines
5.6 KiB
Markdown
Raw Normal View History

2020-01-09 13:50:49 +01:00
Table of Contents
=================
* [Table of Contents](#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)
* [Getting started](#getting-started)
2020-01-09 13:54:34 +01:00
* [Terminal commands](#terminal-commands)
2020-01-09 13:50:49 +01:00
2020-01-08 13:52:06 +01:00
# How to Git started
## Using a GUI
2020-01-09 12:04:01 +01:00
You can use any GUI for git, the ones we use are Fork and Sourcetree <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
- Staging
- Committing
- Git push
- Git pull request
- Branching
- 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-09 13:54:34 +01:00
## Assignments
2020-01-09 12:09:44 +01:00
2020-01-09 13:54:34 +01:00
### Assignment 1: Create a repository
2020-01-08 17:00:26 +01:00
1. Create your own new repository
2. Add a .gitignore file
3. Why you would like a gitignore file
2020-01-09 14:29:45 +01:00
- Not pushing sensitive files
- Not pushing environment files
4. Add a README.md
2020-01-08 16:53:05 +01:00
2020-01-09 13:54:34 +01:00
### Assignment 2: Your first commit
2020-01-08 17:00:26 +01:00
0. Clone repository
0. Edit README file
0. Create a new file(s) and add information
0. Stage README and your file(s)
0. Commit README and your file(s)
2020-01-08 16:53:05 +01:00
2020-01-09 13:54:34 +01:00
### Assignment 3: Merge conflicts
2020-01-08 17:00:26 +01:00
0. Go to the How to Git started repository
2020-01-09 15:33:34 +01:00
0. Add icecream.py to your repository
2020-01-08 17:00:26 +01:00
0. Choose a partner
0. Add him/her as a collaborator
0. Make the partner clone your repository
0. Let both of you edit the same line in the code file
0. Let one of you stage and push the changes
0. Solve the merge conflict
2020-01-08 16:53:05 +01:00
2020-01-09 13:54:34 +01:00
### Assignment 5: Branching
2020-01-08 17:00:26 +01:00
0. Go to the How to Git started repository
0. Add index.html to your shared repository.
0. Let person A create a new branch called header
0. Let person B create a new branch called footer
0. Let person A edit the header of index.html
0. Let person B edit the footer of index.html
0. Stage and push the changes
0. Pull the latest changes
0. Track the branch of your partner
2020-01-08 16:53:05 +01:00
2020-01-09 13:54:34 +01:00
### Assignment 6: Merge branches (Or Rebase)
2020-01-08 17:00:26 +01:00
0. Go to your master branch
0. Merge it with the header branch
0. Commit the merge
0. Merge it with the footer branch
0. Commit the merge
0. Push the changes
0. Delete your old branches
2020-01-08 16:53:05 +01:00
2020-01-09 13:54:34 +01:00
### Assignment 7: Pull requests
2020-01-08 17:00:26 +01:00
0. Let one of you create a new repository (do not add collaborators)
0. Stage and commit a file
0. Let the other person fork the repository and clone it
0. Let him/her change the file and push it
0. Let him/her create a new pull request via the GUI
0. Let the other approve and merge the request
0. Let the other pull the latest changes
2020-01-08 16:53:05 +01:00
2020-01-09 13:54:34 +01:00
### Assignment 8: Undo / Revert commit
### Assignment 9:
2020-01-08 16:53:05 +01:00
Check the logs
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-13 10:08:50 +01:00
```shell
$ git config --global user.name "[name]"
```
2020-01-13 09:41:23 +01:00
Sets the name you want attached to your commit transactions
2020-01-08 13:52:06 +01:00
2020-01-13 10:08:50 +01:00
```shell
$ git config --global user.email "[email address]"
```
2020-01-13 09:41:23 +01:00
Sets the email you want attached to your commit transactions
```shell
2020-01-13 10:08:50 +01:00
$ git config --global color.ui auto
```
Enables helpful colorization of command line output
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-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
```