forked from Workshops/How-To-Git-Started
245 lines
6.7 KiB
Markdown
245 lines
6.7 KiB
Markdown
Table of Contents
|
||
=================
|
||
|
||
* [How to Git started](#how-to-git-started)
|
||
* [Using a GUI](#using-a-gui)
|
||
* [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)
|
||
* [Using the terminal](#using-the-terminal)
|
||
* [Configure tooling](#configure-tooling)
|
||
* [Terminal commands](#terminal-commands)
|
||
* [Branches](#branches)
|
||
* [Glossary](#glossary)
|
||
* [Resources](#resources)
|
||
|
||
# How to Git started
|
||
|
||
## Using a GUI
|
||
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/
|
||
|
||
For other GUIs check out https://git-scm.com/downloads/guis/
|
||
|
||
Our remote git server is located at https://git.web.rug.nl/ <br/>
|
||
You can log in with your usual p-number and password.
|
||
|
||
This README has been written in markdown. <br/>
|
||
To get started see the following cheat sheet: <br/>
|
||
|
||
Cheatsheets: <br/>
|
||
[Markdown](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet)
|
||
|
||
|
||
## Learning objectives
|
||
- Introduction to VCS
|
||
- Create new repository
|
||
- README.md
|
||
- Git ignore file
|
||
- Staging
|
||
- Committing
|
||
- Git push
|
||
- Git pull request
|
||
- Branching
|
||
- Merge / Rebase
|
||
- Undoing Things
|
||
- Amend commits
|
||
- Unstaging
|
||
- Unmodifying a modified file
|
||
- Revert and reset
|
||
- Tag
|
||
- Log
|
||
|
||
## Assignments
|
||
|
||
### Assignment 1: Create a repository
|
||
1. Create your own new repository
|
||
2. Add a .gitignore file
|
||
3. Why you would like a gitignore file
|
||
- Not pushing sensitive files
|
||
- Not pushing environment files
|
||
4. Add a README.md
|
||
|
||
### Assignment 2: Your first commit
|
||
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)
|
||
|
||
### Assignment 3: Merge conflicts
|
||
0. Go to the How to Git started repository
|
||
0. Add icecream.py to your repository
|
||
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
|
||
|
||
### Assignment 5: Branching
|
||
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
|
||
|
||
### Assignment 6: Merge branches (Or Rebase)
|
||
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
|
||
|
||
### Assignment 7: Pull requests
|
||
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
|
||
|
||
### Assignment 8: Undo / Revert commit
|
||
### Assignment 9:
|
||
Check the logs
|
||
|
||
|
||
## Using the terminal
|
||
|
||
### Configure tooling
|
||
|
||
Configure user information for all local repositories
|
||
|
||
```shell
|
||
$ git config --global user.name "[name]"
|
||
```
|
||
Sets the name you want attached to your commit transactions
|
||
|
||
```shell
|
||
$ git config --global user.email "[email address]"
|
||
```
|
||
Sets the email you want attached to your commit transactions
|
||
|
||
```shell
|
||
$ git config --global color.ui auto
|
||
```
|
||
Enables helpful colorization of command line output
|
||
|
||
If you want to save your https credentials run
|
||
```shell
|
||
git config --global credential.helper store
|
||
Omit --global to set the identity only in this repository.
|
||
```
|
||
|
||
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)
|
||
|
||
### Terminal commands
|
||
|
||
See changes that have been made
|
||
```shell
|
||
git diff
|
||
```
|
||
|
||
Adding files to commit
|
||
```shell
|
||
git add file1 file2
|
||
git add *
|
||
```
|
||
|
||
Committing files with commit message, this will stage your changes
|
||
```shell
|
||
git commit -m "your commit message"
|
||
```
|
||
unstage by using
|
||
```shell
|
||
use "git reset HEAD <file>..." to unstage
|
||
```
|
||
|
||
|
||
### 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
|
||
```shell
|
||
$ git branch [branch-name]
|
||
$ git checkout -b [branch-name]
|
||
```
|
||
|
||
Switches to the specified branch and updates the working directory
|
||
```shell
|
||
$ git checkout [branch-name]
|
||
```
|
||
|
||
|
||
Combines the specified branch’s history into the current branch. This is usually done in pull requests, but is an important Git operation.
|
||
```shell
|
||
$ git merge [branch]
|
||
```
|
||
|
||
|
||
Deletes the specified branch
|
||
```shell
|
||
$ git branch -d [branch-name]
|
||
```
|
||
|
||
|
||
Show all available branches
|
||
```shell
|
||
git branch -a
|
||
```
|
||
|
||
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>
|
||
```
|
||
|
||
Check the log in graph form
|
||
```shell
|
||
git log --graph --oneline
|
||
```
|
||
|
||
|
||
## 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
|
||
|
||
|
||
## Resources
|
||
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/>
|
||
|