Using git version control
Last updated
Was this helpful?
Last updated
Was this helpful?
如果你不太習慣從terminal (Mac)或cmd (Win)等command line來下指令,你可以來下載或管理自己的repository,視窗化的工具有助於你初步了解git這種版本控制工具要如何用。
我們將Terminal(Mac)或cmd(Win)這種工具稱為命令列工具(Command line)。
Command line要如何下可參考/的說明。初始化一個repository有兩種時機,一種是你要把電腦裡的一個資料夾放到github上,另一種是,你要把網路上的一個github repo clone到你的電腦裡,分別是以下兩個指令。
Command
Description
git init
Initialize a local Git repository
git clone ssh://git@github.com/[username]/[repository-name].git
Create a local copy of a remote repository
除了初始化外,git有三個主要的動作
commit:提交任何變更,commit後不會寫到github,而且可以退回。
push:在提交變更後,把這些變更版本覆蓋到github上。
pull:把github上別人改過的版本拉下來,覆蓋掉自己電腦上的版本。
Command
Description
git status
Check status
git add [file-name.txt]
Add a file to the staging area
git add -A
Add all new and changed files to the staging area
git commit -m "[commit message]"
Commit changes
git rm -r [file-name.txt]
Remove a file (or folder)
Command
Description
git push origin [branch name]
Push a branch to your remote repository
git push -u origin [branch name]
Push changes to remote repository (and remember the branch)
git push
Push changes to remote repository (remembered branch)
git push origin --delete [branch name]
Delete a remote branch
git pull
Update local repository to the newest commit
git pull origin [branch name]
Pull changes from remote repository
git remote add origin ssh://git@github.com/[username]/[repository-name].git
Add a remote repository
git remote set-url origin ssh://git@github.com/[username]/[repository-name].git
Set a repository's origin branch to SSH