---
# System prepended metadata

title: Git with Github
tags: [Linux, git]

---

# Git with Github

###### tags: `Linux` `git`

> This note is basic operation of git 

[TOC]
## :memo: Prerequisite Tools
- [x] Git
```bash
$ apt-get install git
```
:::info
if is windows ➜ click [here](https://git-scm.com/download/win) to download
::: 

### Step 1: Config user info
```bash
$ git config --global user.name "<Your Name>"
```
```bash
$ git config --global user.email "<your@email>"
```

### Step 2: Create local repository
```bash
$ mkdir myrepo
```
```bash
$ cd myrepo
```
```bash
$ git init
```
### Step 3: Add file to git
```bash
$ git add .
```
:::info
It is mean that all files in the current folder can be tracked by git.
::: 
You can also replace like this
```bash
$ git add <filename>
```
If you want to cancel
```bash
$ git rm --cached <filename>
```
### Step 4: New commits
```bash
$ git commit -a -m "<your commit>"
```
### Step 5: Connect local to remote repository
```bash
$ git remote add origin <remote url>
```

### Step 6: push to remote repository
```bash
$ git push origin master
```

---

## 復原操作
* `git reset HEAD^`
    * `--mixed`：預設，這個模式會把暫存區的檔案丟掉，但不會動到工作目錄的檔案，也就是說 Commit 拆出來的檔案會留在工作目錄，但不會留在暫存區。
    * `--soft`：工作目錄跟暫存區的檔案都不會被丟掉，所以看起來就只有 HEAD 的移動而已。也因此，Commit 拆出來的檔案會直接放在暫存區。
    * `--hard`：不管是工作目錄以及暫存區的檔案都會丟掉。

---

## Reference

- TechBridge技術共筆部落格 ➜ [Git與Github版本控制基本指令與操作入門教學](https://blog.techbridge.cc/2018/01/17/learning-programming-and-coding-with-python-git-and-github-tutorial/)
