1、命令行
1.1、HTTPS Git
获得令牌后,您可以在通过 HTTPS 执行 Git 操作时输入它而不是密码。
例如,在命令行中,您将输入以下内容:
$ git clone https://github.com/username/repo.git
Username: your_username
Password: your_token
个人访问令牌只能用于 HTTPS Git 操作。如果您的存储库使用 SSH 远程 URL,则需要将远程从 SSH 切换到 HTTPS。
-
List your existing remotes in order to get the name of the remote you want to change.
$ git remote -v > origin [email protected]:USERNAME/REPOSITORY.git (fetch) > origin [email protected]:USERNAME/REPOSITORY.git (push)
-
Change your remote's URL from SSH to HTTPS with the
git remote set-url
command.$ git remote set-url origin https://github.com/USERNAME/REPOSITORY.git
-
Verify that the remote URL has changed
$ git remote -v # Verify new remote URL > origin https://github.com/USERNAME/REPOSITORY.git (fetch) > origin https://github.com/USERNAME/REPOSITORY.git (push)
1.2、SSH
1.2.1、生成公钥
ssh-keygen -t rsa
通过结果显示及cat命令查看可知public key存放于 id_rsa.pub 中
1.2.2、将公钥部署到github
- github右上角账户管理
- Setting下面找到左侧“SSH and GPG keys”菜单
- 接着点击“Add SSH key”,在”title”栏输入一个自己喜欢的标题,“key”栏中粘贴刚刚复制的公钥内容,最后点击“Add key”按钮。(粘贴时选择为纯文本),最后生成的结果。
1.2.3、测试连接
ssh -vT [email protected]
2、授权第三方(IDEA)
2.1、配置git路径
2.2、克隆项目
2.3、上传项目到git仓库
在你的idea里新建git仓库,这是新建本地仓库,等会会同步到线上git仓库
2.4、然后push到线上仓库
- 如果第一次提交项目的话,这里是没有远程地址。点击蓝色的字,定义远程地址
2.5、更新项目、解决冲突
- 按照图片中的步骤,顺序不能乱,先stash,然后pull,最后unstash
- stash会让你输入标记名称,unstash的时候选择想要的标记
- 如果代码有冲突,我们需要编辑冲突,我们一般选择merge,就是合并的意思,当然你也可以不合并直接使用线上的或者暂存里的代码。
- 合并代码的时候,图片中描述了,三屏分别对应的是什么。
评论区