原創(chuàng)不易,轉(zhuǎn)發(fā)請表明出處
最近在項(xiàng)目中使用git,遇到了一些坑,感覺需要總結(jié)下提高效率了
入門篇
- 本地的公鑰拷貝到git倉庫中
這樣就可以不用賬戶密碼登陸了掀亥,首先在本地生成公鑰私鑰對撩扒,執(zhí)行以下語句:
ssh-keygen -t rsa -C 'wusi'
注意 wusi可以改成你自己的名字
cd ~/.ssh
拷貝 id_rsa.pub的內(nèi)容
在github -> 個(gè)人 -> settings -> SSH and GPG keys -> new SSH key title隨意,key拷貝過去 - git本地倉庫初始化
mkdir git-learning
cd git-learning
git init
touch readme
添加文件到版本控制
git add readme
- 查看代碼變動情況
git status
- 提交代碼到本地倉庫
git commit -m 'add readme'
提示信息:
[master (root-commit) e0811b5] add readme1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 readme
- 將本地倉庫推送到遠(yuǎn)程倉庫
首先在github上建立倉庫逛尚,我建立的倉庫名稱為 git-learning
// 遠(yuǎn)程添加倉庫
git remote add origin git@github.com:wusi05/git-learning.git
// 推送代碼
git push -u origin master
提示信息
The authenticity of host 'github.com (13.250.177.223)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXWGl7E1IGOCspRomTxdCARKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,13.250.177.223' (RSA) to the list of known hosts.
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 201 bytes | 201.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To github.com:wusi05/git-learning.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
查看github代碼推送成功了
- 將本地分支和遠(yuǎn)程分支建立鏈接
git branch --set-upstream-to=origin/<branch> local-branch
提高篇
推送本地倉庫到遠(yuǎn)程
- git init
- git add .
- git commit -m 'first commit'
- git remote add origin 你的遠(yuǎn)程庫地址
- git pull --rebase origin master
- git push -u origin master
- git status