Git 操作

发布时间:2024年01月19日

1. 配置 upstream

首先需要从主库 fork 代码到用户空间下。
http://10.166.15.223:6880/autoeval/autoeval.git
fork =》
http://10.166.15.223:6880/cliffordl/autoeval.git
拉取代码,应该拉取用户的代码吧

[user@node3 ~]$ git clone http://10.166.15.223:6880/autoeval/autoeval.git
Cloning into 'autoeval'...
Username for 'http://10.166.15.223:6880': cliffordl
Password for 'http://cliffordl@10.166.15.223:6880': password
remote: Enumerating objects: 21, done.
remote: Counting objects: 100% (21/21), done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 21 (delta 2), reused 0 (delta 0)
Unpacking objects: 100% (21/21), done.

首先查看 git remote 信息

[user@node3 autoeval]$ git remote -v
origin  http://10.166.15.223:6880/cliffordl/autoeval.git (fetch)
origin  http://10.166.15.223:6880/cliffordl/autoeval.git (push)

添加主库 upstream。(是否需要为主库添加 upstream 并且推到远程。)

[user@node3 autoeval]$ git remote add upstream http://10.166.15.223:6880/autoeval/autoeval.git
[user@node3 autoeval]$ git remote -v
origin  http://10.166.15.223:6880/cliffordl/autoeval.git (fetch)
origin  http://10.166.15.223:6880/cliffordl/autoeval.git (push)
upstream        http://10.166.15.223:6880/autoeval/autoeval.git (fetch)
upstream        http://10.166.15.223:6880/autoeval/autoeval.git (push)
[user@node3 autoeval]$

禁止 push

[user@node3 autoeval]$ git remote set-url --push upstream no_push
[user@node3 autoeval]$
[user@node3 autoeval]$ git remote -v
origin  http://10.166.15.223:6880/cliffordl/autoeval.git (fetch)
origin  http://10.166.15.223:6880/cliffordl/autoeval.git (push)
upstream        http://10.166.15.223:6880/autoeval/autoeval.git (fetch)
upstream        no_push (push)

2.上传代码

将远程 upstream 的代码替换到当前 master 之上。也就是以 upstream 为最新。

[user@node3 autoeval]$ git checkout -b fix-1

拉取主库 upstream 代码

[user@node3 autoeval]$ git checkout master
Switched to branch 'master'
[user@node3 autoeval]$ git fetch upstream
Username for 'http://10.166.15.223:6880': cliffordl
Password for 'http://cliffordl@10.166.15.223:6880': password
From http://10.166.15.223:6880/autoeval/autoeval
 * [new branch]      master     -> upstream/master

将主库 upstream 代码合并到本地 master 之上

[user@node3 autoeval]$ git rebase upstream/master
Current branch master is up to date.

将本地 master 推到用户仓库(而非主库)

[user@node3 autoeval]$ git push origin master
Username for 'http://10.166.15.223:6880': cliffordl
Password for 'http://cliffordl@10.166.15.223:6880': password
Everything up-to-date
[user@node3 autoeval]$
文章来源:https://blog.csdn.net/cliffordl/article/details/135692670
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。