# GitHub Tutorial
## Git and Github
Git is a split version control software, originally created by Linus Torvalds (also the developer of the Linux system). Its original purpose is to better manage the development of the Linux kernel. It has excellent merge tracking and merge code ( Use code snapshots to compare the differences in historical versions).
Github is a platform service that supports git code access and remote hosting. Many open source projects use Github for code management.
ref:
[https://blog.techbridge.cc/2018/01/17/learning-programming-and-coding-with-python-git-and-github-tutorial/](https://blog.techbridge.cc/2018/01/17/learning-programming-and-coding-with-python-git-and-github-tutorial/)
## Install git
### Download at [http://git-scm.com/](http://git-scm.com/).
[https://progressbar.tw/posts/1](https://progressbar.tw/posts/1)
## Open Git CMD
> ==Right click== > ==Git Bash Here==
## Initialize Git repository
```cmd
$ git init
```
## View repositpry file tracking status
```cmd
$ git status
```
## Add file to tracking list
```cmd
$ git add <file name>
$ git add .
```
## Build a set of version update(Commitment)
```cmd
$ git commit -m "message of version update"
$ git log
```
### When happen following error:
```cmd
Author identity unknown
*** 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.
fatal: unable to auto-detect email address (got 'User@Chulabserver.(none)')
```
### try:
```cmd
$ git config --global user.email "you@example.com"
```
### Exit
> ==Q==
## Branch
### View branch
```cmd
$ git branch
```
#### Default is "master" in your git of location.
### Add branch
```cmd
$ git branch <branch name>
```
#### Default is "main" instead of "master" in github.
### Delete branch
```cmd
$ git branch -d <branch name>
```
### Switch branch
```cmd
$ git checkout <branch name>
```
## Check remote space
```cmd
$ git remote -v
```
## Add remote space
### Usually use "origin" as remote space name.
```cmd
$ git remote add <remote space name> <GitHub Reposutory url>
```
## Modify remote space
```cmd
$ git remote set-url origin <GitHub Reposutory url>
```
## Clean cache in local
```cmd
$ git rm -r --cached .
$ git add .
$ git commit -m "message of version update"
```
[https://www.itread01.com/content/1544146150.html](https://www.itread01.com/content/1544146150.html)
## Upload to GitHub
```cmd
$ git push <remote space name> <remote branch name>
$ git push origin main
```
### When happen following error:
```cmd
error: failed to push some refs to 'https://github.com/eddiekao/dummy-git.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
```
### try:
```cmd
$ git push -f <remote space name> <remote branch name>
```
#### or
```cmd
$ git push --force <remote space name> <remote branch name>
```
### When happen following error:
```cmd
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
```
### try:
[https://www.youtube.com/watch?v=ytSoabxSQ6E](https://www.youtube.com/watch?v=ytSoabxSQ6E)
## First download GitHub project
```cmd
$ git clone <GitHub Reposutory url> <local file name>
```
## Download and merge GitHub project
```cmd
$ git pull <remote space name> <remote branch name>
```
## SOP of building a new repository
### step1: New a repository in GitHub.
#### Tick "Add a README file".
#### Tick "Add .gitignore" and choose language.
#### Tick "Choose a license" and choose "MIT License"
### Step2: Build a repository in location.
#### 1) Add a folder for the new project.
#### 2) Open Git CMD of new folder
#### 3) Clone repository from GitHub to folder.
```cmd
$ git clone <GitHub Reposutory url> <local file name>
```
### Step3: Initialize setting
#### 1) Add a ".vscode" file.
[https://hackmd.io/eeg0Q5obT9CEXs70EzPXpQ](https://hackmd.io/eeg0Q5obT9CEXs70EzPXpQ)
#### 2) New ".vscode" in ".gitignore" file.
#### 3) Commit to GitHub.
```cmd
$ git add .
```
```cmd
$ git commit -m "message of version update"
```
```cmd
$ git push <remote space name> <remote branch name>
git push origin main
```
ref:
[https://www.youtube.com/watch?v=NugoF40e6Dk](https://www.youtube.com/watch?v=NugoF40e6Dk)