How-To-Git-Started/README.md

163 lines
3.6 KiB
Markdown
Raw Normal View History

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/>
You can log in with your p-number as password.
2020-01-08 17:01:45 +01:00
### Learning objectives
- Introduction to VCS
- Create new repository
- Git ignore file
- Staging
- Committing
- Git push
- Git pull request
- Branching
- Merge / Rebase
2020-01-09 12:04:01 +01:00
- Amend commits
- Revert and reset
2020-01-09 10:31:59 +01:00
- Tag
- Log
2020-01-08 16:53:05 +01:00
### Assignments
2020-01-09 12:09:44 +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
4. Not pushing sensitive files
5. Not pushing environment files
6. Add a README
2020-01-08 16:53:05 +01:00
2020-01-09 12:09:44 +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 12:09:44 +01:00
#### Assignment 3: Merge conflicts
2020-01-08 17:00:26 +01:00
0. Go to the How to Git started repository
0. Add factorial.py and fibonacci.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
2020-01-08 16:53:05 +01:00
2020-01-09 12:09:44 +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 12:09:44 +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 12:09:44 +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 12:09:44 +01:00
#### Assignment 8: Undo 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
### Getting started
2020-01-08 13:52:06 +01:00
Set up your git info
2020-01-08 13:55:14 +01:00
```shell
2020-01-08 13:52:06 +01:00
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
```
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-08 16:54:53 +01:00
Or you can add an SSH key
2020-01-08 14:03:33 +01:00
## Saving changes
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 13:09:47 +01:00
Committing files with commit message
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-09 13:12:45 +01:00
Creating a new branch
```shell
git branch <branchname>
git checkout -b <branchname>
```
Going to different branch
```shell
git checkout <branchname>
```
Seeing available branches
```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-09 12:53:06 +01:00
Check the log in graph form
```shell
git log --graph --oneline
```