# Git 基本操作
資訊之芽 2022 Python 語法班
Author: Sean 韋詠祥
Note:
日期:2022-05-08
----
## 課程錄影
{%youtube b7NDvFd7bJw %}
###### Link: https://www.youtube.com/watch?v=b7NDvFd7bJw
----
## 安裝 Git 工具
----
## macOS 安裝方式
先開啟 [iTerm2](https://iterm2.com/) 或 Terminal 終端機

輸入 git 指令,內建的 Xcode 將會跳出安裝資訊
```bash
git --version
```
----
## Windows 安裝方式
搜尋 Git for Windows

###### Link: https://gitforwindows.org/
----
## 依指示安裝
基本上都下一步,編輯器這邊可以改成自己慣用的

----
## Linux 安裝方式
相信你知道怎麼做的 :D
```bash
# Debian / Ubuntu
apt install git
```
```bash
# Fedora
dnf install git
```
```bash
# Arch Linux
pacman -S git
```
```bash
# Alpine
apk add git
```
---
# 註冊 GitHub 帳號

###### 網站:https://github.com/
----
## 填寫帳號資料

驗證碼:選出螺旋星系
----
## 收驗證信

----
## 個人分析資料

可點擊下方 Skip 跳過
---
# 基本 Bash 指令
- 切換目錄
- 顯示檔案內容
- 查看目前狀態
- 以下有 3 大部分,請跟著實作一次
先大概理解就好,也可以上網查「Bash XXX 用法」
----
## Part 1
```bash
ls # 列出目前目錄下的檔案
ls -a # 包含隱藏檔案
ls -l # 顯示詳細資訊
ls -al # 我全都要!
```
<br>
```bash
touch myfile # 建立空檔案
```
```bash
mkdir mycode # 建立資料夾
```
<br>
```bash
mv myfile file1 # 移動檔案
```
```bash
cp file1 file2 # 複製檔案
```
----
## Part 2
```bash
pwd # 顯示當前目錄
```
```bash
cd mycode # 進入資料夾
cd .. # 回到前一層目錄
cd # 不加參數,代表回到家目錄
```
<br>
```bash
echo Hey
echo "Hello World"
```
----
## Part 3
```bash
cat /etc/passwd # 印出檔案內容
```
```bash
less /etc/passwd # 慢慢查看檔案內容
```
<br>
```bash
rm file1 # 刪除檔案
```
```bash
rmdir mycode # 刪除空資料夾
```
---
# 開始上課!
資訊之芽 2022 Python 語法班
Author: Sean 韋詠祥
----
## 你有沒有看過...

----
## 什麼是版本控制?

----
## 傳統中央控管型

----
## 分散式版本控制系統

----
## 核心使用概念

---
# 開始使用 Git
----
## 環境設定
```bash
git config --global user.name "Sean" # 你的暱稱
git config --global user.email me@sean.taipei
```
```bash
git config --global color.ui true
git config --global init.defaultBranch master
```
```bash
git config --global alias.lg "log --color --graph --all --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --"
```
<!-- .element: class="wrap-code" -->
----
## 環境設定(續)
```bash
git config --global core.editor vim
git config --global merge.tool vimdiff
git config --global core.excludesFile = ~/.gitignore
```
```bash
git config --global gc.auto 0
git config --global pull.ff only
git config --global rerere.enable true
git config --global rebase.autosquash true
```
```bash
git config --global checkout.defaultRemote origin
git config --global url."git@github.com:".insteadOf "https://github.com/"
```
<!-- .element: class="wrap-code" -->
----
## 建立第一個本地 Repo
Git Repository
```bash
# 建立資料夾並初始化 git
mkdir py-project
cd py-project
git init
```
```bash
# 建立 main.py 檔案
vim main.py
git add main.py
```
```bash
git commit
# 在編輯器中輸入 commit 訊息
```
```bash
# 完成!
```
----
## 稍微改點東西
先用編輯器打開 `main.py` 檔案
讓他輸出 0 到 4 這五個數字,每次換行
完成後用 git 保存版本紀錄
```bash
git status
git add main.py
git commit
```
----
## 需求變更
輸入:一個正整數 N
輸出:從 0 到 N-1 的數字,每次換行
```bash
git diff
git add -p main.py
git commit
```
----
## 再次修改
輸入:一個正整數 N
輸出:從 1 到 N 的數字,每次換行
```bash
git add -p .
git commit -m '###'
git show
git show HEAD~1
```
---
# 建立 GitHub Repo

----
## 設定遠端 Repo 網址

```bash
git remote add origin https://github.com/#####/######.git
git remote -v
git push -u origin master
```
----
## 加入說明檔案

```bash
touch README.md # 去編輯 README.md 檔案
git add README.md
git commit
git push
```
----
## LICENSE 授權條款

```bash
git fetch --all
git pull
git log
```
----
## 完成!
讓我們進到 Git 進階用法
---
## Git-flow

----
# Git Branch
小練習:
輸入前詢問「Input N: 」
輸出 0 到 N-1
```bash
git switch
git switch -c feat-prompt-input
```
```bash
git reset
git status
git restore
git clean -x -i -d
```
----
## Git Stash
```bash
git stash
git stash pop
```
----
## Git Rebase
```bash
git rebase -i master
```
---
# Thanks
投影片連結:https://hackmd.io/@Sean64/git-sprout2022
<!-- .element: class="r-fit-text" -->
<br>
[](https://creativecommons.org/licenses/by/4.0/deed.zh_TW)
###### 這份投影片以 [創用 CC - 姓名標示](https://creativecommons.org/licenses/by/4.0/deed.zh_TW) 授權公眾使用,原始碼及講稿請見 [此連結](https://hackmd.io/@Sean64/git-sprout2022/edit)。
<style>
.reveal pre.wrap-code code {
white-space: pre-wrap;
}
</style>
{"metaMigratedAt":"2023-06-17T00:29:50.676Z","metaMigratedFrom":"YAML","breaks":true,"description":"Sean 韋詠祥 / 2022-05-08","title":"Git 基本操作 - 資訊之芽 2022 Python 語法班","contributors":"[{\"id\":\"8a6148ae-d280-4bfd-a5d9-250c22d4675c\",\"add\":6708,\"del\":1629}]"}