本地仓库与远程仓库那些事

262 阅读1分钟

一、Git拉取远程分支到本地

1、查看本地分支

git branch

2、查看远程分支

git branch -a

3、当我想从远程仓库拉取一条本地不存在的分支时

git checkout -b 本地分支名 origin/远程分支名

4、查看分支映射关系

git branch -vv

5、建立本地分支与远程分支的映射关系

git branch --set-upstream-to=origin/远程分支名 本地分支名

二、Git本地新建分支到远程

1、新建并切换到本地分支

git checkout -b 本地分支名

2、将本地分支推送到远程

git pull   //先拉取远程分支的更新
git push --set-upstream orign 本地分支名  //将本地新建分支推送到远程,并建立跟踪关系

3、删除本地分支

git branch -d 本地分支名
git branch -D 本地分支名   // 强制删除

4、删除远程分支

git push origin --delete 远程分支名

三、Git生成 SSH Key

1、检查你是否已有公用SSH密钥

ls -al~/ .ssh

2、查看已生成的SSH Key

cat ~/.ssh/id_rsa.pub

3、生成 SSH Key

ssh-keygen -t rsa -C "youremail@example.com"
然后三次回车

4、剪贴已生成的 SSH Key

clip < ~/.ssh/id_rsa.pub