# git [為你自己學 Git](https://gitbook.tw/chapters/using-git/init-)repository [git remote](/MFJ1VhajSyyqFSaXYgH-Vg) [git fetch](/yjLoNcmtTsOBnCC0sqEwDw) ## 基本指令 ```git= # Git 設定 git config --global user.name "xxx" git config --global user.email "xxx@gmail.com" # 顯示目前設定 git config --list # 查看可用指令 git help # 自訂指令 git config --global alias.ch checkout git config --global alias.br branch git config --global alias.st status # 修改最新的 commit 紀錄 git commit --amend -m "new message" # 把檔案加入最近的 commit git commit --amend --no-edit # 查看 commit 紀錄 git log # 丟棄工作區檔案 git checkout . # 列出所有分支 git branch # 創建分支 git branch <name> # 改變分支 git checkout <name> # 創建 branch,並移動 git checkout -b <name> ``` ## 基本操作 ```git= # 將 repo clone 到本地端 git clone <depositry https or ssh link> # 新增一個檔案 echo "hello" > text.txt # 上傳檔案到 main git add . git commit -m "create a text" git push origin main ``` ```git= # 查看狀態 git status git branch -r # 回傳自己的 localBranchName git rev-parse --abbrev-ref HEAD # 如果無法推上去,就先拉下來 git pull --rebase # remove branch master git push -u origin main git push origin --delete master ``` ## files -> branch ```bash= # 1. initialize the repository git init # 2. add all the files to the given folder git add . # 3. view all the files which are going to be staged to the first commit git status # 4. dds the change to the local repository git commit -m 'your message' # 5. name 'origin' as a connection to 'url' # if your is John, you can name as 'johs' git remote add origin 'url' # 6. push file to branch "master" git push -u 'origin' 'branch_name' ``` ## Copy remote repository's URL from GitHub 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up