Create remote repo
pwd:/Users/zhanglx/workspace/gittest/ git init --bare
Clone repo from remote repo
git clone /Users/zhanglx/workspace/gittest/
Init a local git repo and add a remote
This is equal to "Clone"
mkdir myrepo cd myrepo/ git init git remote add origin /Users/zhanglx/workspace/gittest/
New branch and switch to this branch
git branch test git checkout test
Type git branch
to check which branch you are working on.
Add, modify, commit, reset and checkout history
Git文件狀態
Git文件的狀態分為untracked和tracked, untracked文件是指新建的文件,尚未被git管理起來。
tracked又分為三種狀態:
已提交(committed),已修改(modified)和已暫存(staged)。已提交表示文件已被安全地保存在本地數據庫中了;已修改表示修改了某個文件,但沒有提交保存;已暫存表示把已修改的文件放在下次提交時要保存的清單中。
Github
git remote show origin
查看相關信息 git push origin master
將commit的代碼,push到github上。 git pull origin master
將github上的代碼,update到本地。
Delete
git delete file
然后commit的,將無法恢復。 rm file
, 可以通過git checkout -- file
進行恢復。 git rm --cached file
,只是在緩存中刪除,
恢復更改的文件 git checkout — //未git add的文件
git reset HEAD //已經git add的文件,可以用這個取消add,然后用上一條命令恢復
Push master branch of locale repo to remote origin
git push origin master
Pull (if there are some conflicts, git will call git merge automatically)
git pull origin master
創建SSH key
ssh-keygen 生成的SSH key文件保存在中~/.ssh/id_rsa.pub
添加SSH key到github
接着拷貝.ssh/id_rsa.pub文件內的所以內容 打開github帳號管理中的添加SSH key界面的步驟如下: 1. 登錄github 2. 點擊右上方的Accounting settings圖標 3. 選擇 SSH key 4. 點擊 Add SSH key