Git—01—如何连接gitee等远程仓库


 一、连接

1、首先安装git和vs code

2、登录gitee账户,添加本电脑的ssh公钥;

  • 打开本机的git终端,输入命令获取sshkey;
    ssh-keygen -t rsa -C "xxxxx@xxxxx.com" 
  • 然后生成的ssh公钥默认会保存在~文件夹中,所以cd ~
  • 然后cat  .ssh/id_rsa.pub 文件内容获取公钥;
  • 粘贴到gitee上;

3、新建一个文件夹,然后输入命令:git init

去初始化一个git仓库

4、输入命令去连接远程仓库:

  • git  remote  add hostname url(eg:  git remote add origin git@github.com:michaelliao/learngit.git

查看本地已经连接的远程仓库:

  • git remote -v    ( 查看本地git中,已经关联的远程仓库信息)
  • git remote rm origin   (删除origin这个远程库)

5、拉取远程仓库代码到本地某个分支;

  • git pull hostname branchname(eg:  git pull orign master)

6、分支操作:

git branch -a 列出所有分支

git switch -c 新分支名字  (创建一个新分支)

git switch 分支名字  (切换到某个分支)

7、推送代码到远程仓库

  • git add  filename
  • git add  . (添加所有文件到stage暂存区)
  • git commit -m"本次提交的说明"
  • git push hostname  branchname(eg: git push ori_mb master)(hostname指定了你要推向哪个远程仓库。这里指的ori_mb)

 

 

 二、无法连接的原因

注意:一个电脑账户,如何创建多个git ssh密钥

https://www.cnblogs.com/dbave/p/11718492.html

注意:如果拉代码的时候,告诉

git@gitlab.com: Permission denied (publickey).

 

并不是说我们git没有找到相应地址的私钥,还有一种可能,我们的帐号并没有添加到这个项目的项目成员中,所以我们这个账号无法下载项目,找管理员把我们邮箱账号拉到项目里即可;

 

 

参考:

https://www.liaoxuefeng.com/wiki/896043488029600/1163625339727712

posted @ 2020-09-10 21:55  Eric-Shen  阅读(2239)  评论(0编辑  收藏  举报