導語
git是編碼人員非常重要的工具,最近在使用的過程中發現有些命令經常忘記,所以寫下此文,,一起分享,以后也可查閱
常用命令
- 配置身份
git config --global user.name "kkxiaojun"
git config --global user.email "985531883@qq.com"
- 創建repository(倉庫)
git init 創建倉庫
git commit -m "First commit."-m參數來加上提交的描述信息
git add src **添加整個目錄 **
git add . 添加所有的文件
git commit -m "ssh員工管理系統實現" 真正提交
git remote add origin git@github.com:kkxiaojun/EMSystemDo.git 連接遠程
git push -u origin master 同步到遠程
第一次加-u,二次后:git push origin master
- 之后每次修改或添加
git add
git commit
git push origin master
- 從遠程庫克隆
git clone git@github.com:kkxiaojun/EMSystemDo.git
遠程分支
git branch iss53 創建分支
git checkout iss53 切換到分支
git merge 合并分支
命令
Git遠程分支管理
git pull # 抓取遠程倉庫所有分支更新并合并到本地
git pull --no-ff # 抓取遠程倉庫所有分支更新并合并到本地,不要快進合并
git fetch origin # 抓取遠程倉庫更新
git merge origin/master # 將遠程主分支合并到本地當前分支
git co --track origin/branch # 跟蹤某個遠程分支創建相應的本地分支
git co -b <local_branch> origin/<remote_branch> # 基于遠程分支創建本地分支,功能同上
git push # push所有分支
git push origin master # 將本地主分支推到遠程主分支
git push -u origin master # 將本地主分支推到遠程(如無遠程主分支則創建,用于初始化遠程倉庫)
git push origin <local_branch> # 創建遠程分支, origin是遠程倉庫名
git push origin <local_branch>:<remote_branch> # 創建遠程分支
git push origin :<remote_branch> #先刪除本地分支(git br -d <branch>),然后再push刪除遠程分支
問題解決
-
git error : ssh: Could not resolve hostname?
-
檢查ssh-key (這是有的,沒有則需要生成)
ssh-key - 生成ssh-key
$ ssh-keygen -t rsa -C "xxxxxx@yy.com" #建議填寫自己真實有效的郵箱地址
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/xxxx_000/.ssh/id_rsa): 直接回車
Enter passphrase (empty for no passphrase): #輸入密碼(可以為空)
Enter same passphrase again: #再次確認密碼(可以為空)
Your identification has been saved in /c/Users/xxxx_000/.ssh/id_rsa. #生成的密鑰
Your public key has been saved in /c/Users/xxxx_000/.ssh/id_rsa.pub. #生成的公鑰
The key fingerprint is:
e3:51:33:xx:xx:xx:xx:xxx:61:28:83:e2:81 xxxxxx@yy.com -
- 找出ssh-key
[root@localhost ~]# cd ~/.ssh/
id_rsa id_rsa.pub known_hosts
[root@localhost ~]# cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAyFWY3VgY8D4IDqQKOCW3bTovL7cZunWaCIl69A16POCJIpNSymEZw2wUYfGdvwmX93kp4xEqPK9/rX30duLfRWgMNV8/YE6AGZo90YXfMmti/OXHvnTrHI82LgiabX6UH1QfXQhSAtq3AHWc4KIu/0HcZUYBgTalmpNlmsol7dgTpwMQPriwNdE65dc0ZeHUxY3cHNI+v5lXjSYlRBaoJnowY5qim4ld4hH2QGYNQ+GuzPXtCkBIbkG+uiADKrDyPVGOgjbC7To4BsKoIO2/0NkRCV0/G01kL393oWmhhIlk/OhhJZ5Z6QnC1EubX/e9n0lglbdXo7St8WjT4/3qtQ== wuzhiyi51@gmail.com
- 將SSHKey文件復制添加到GitHub上的SSH keys即可
2.[Git push halts on “Writing Objects: 100%]
git config --global http.postBuffer 524288000即可解決