導(dǎo)語(yǔ)
git是編碼人員非常重要的工具,最近在使用的過(guò)程中發(fā)現(xiàn)有些命令經(jīng)常忘記,所以寫(xiě)下此文桌吃,,一起分享苞轿,以后也可查閱
常用命令
- 配置身份
git config --global user.name "kkxiaojun"
git config --global user.email "985531883@qq.com"
- 創(chuàng)建repository(倉(cāng)庫(kù))
git init 創(chuàng)建倉(cāng)庫(kù)
git commit -m "First commit."-m參數(shù)來(lái)加上提交的描述信息
git add src **添加整個(gè)目錄 **
git add . 添加所有的文件
git commit -m "ssh員工管理系統(tǒng)實(shí)現(xiàn)" 真正提交
git remote add origin git@github.com:kkxiaojun/EMSystemDo.git 連接遠(yuǎn)程
git push -u origin master 同步到遠(yuǎn)程
第一次加-u茅诱,二次后:git push origin master
- 之后每次修改或添加
git add
git commit
git push origin master
- 從遠(yuǎn)程庫(kù)克隆
git clone git@github.com:kkxiaojun/EMSystemDo.git
遠(yuǎn)程分支
git branch iss53 創(chuàng)建分支
git checkout iss53 切換到分支
git merge 合并分支
命令
Git遠(yuǎn)程分支管理
git pull # 抓取遠(yuǎn)程倉(cāng)庫(kù)所有分支更新并合并到本地
git pull --no-ff # 抓取遠(yuǎn)程倉(cāng)庫(kù)所有分支更新并合并到本地逗物,不要快進(jìn)合并
git fetch origin # 抓取遠(yuǎn)程倉(cāng)庫(kù)更新
git merge origin/master # 將遠(yuǎn)程主分支合并到本地當(dāng)前分支
git co --track origin/branch # 跟蹤某個(gè)遠(yuǎn)程分支創(chuàng)建相應(yīng)的本地分支
git co -b <local_branch> origin/<remote_branch> # 基于遠(yuǎn)程分支創(chuàng)建本地分支,功能同上
git push # push所有分支
git push origin master # 將本地主分支推到遠(yuǎn)程主分支
git push -u origin master # 將本地主分支推到遠(yuǎn)程(如無(wú)遠(yuǎn)程主分支則創(chuàng)建瑟俭,用于初始化遠(yuǎn)程倉(cāng)庫(kù))
git push origin <local_branch> # 創(chuàng)建遠(yuǎn)程分支翎卓, origin是遠(yuǎn)程倉(cāng)庫(kù)名
git push origin <local_branch>:<remote_branch> # 創(chuàng)建遠(yuǎn)程分支
git push origin :<remote_branch> #先刪除本地分支(git br -d <branch>),然后再push刪除遠(yuǎn)程分支
問(wèn)題解決
-
git error : ssh: Could not resolve hostname?
-
檢查ssh-key (這是有的摆寄,沒(méi)有則需要生成)
ssh-key - 生成ssh-key
$ ssh-keygen -t rsa -C "xxxxxx@yy.com" #建議填寫(xiě)自己真實(shí)有效的郵箱地址
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: #再次確認(rèn)密碼(可以為空)
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文件復(fù)制添加到GitHub上的SSH keys即可
2.[Git push halts on “Writing Objects: 100%]
git config --global http.postBuffer 524288000即可解決