IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 开发工具 -> Git - 入门到熟悉_远程仓库管理 -> 正文阅读

[开发工具]Git - 入门到熟悉_远程仓库管理

在这里插入图片描述


Pre

Git - 入门到熟悉_Git基本概念与核心命令

Git - 入门到熟悉_分支管理


常用命令

在这里插入图片描述

#查看远程配置 
git remote [-v]
#添加远程地址
git remote add origin http:xxx.xxx
#删除远程地址
git remote remove origin 
#上传新分支至远程
git push --set-upstream origin master 
#将本地分支与远程建立关联
git branch --track --set-upstream-to=origin/test test


演示

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ git remote -v  #查看远程配置 
origin  https://gitee.com/yangshangwei/gitProject.git (fetch)
origin  https://gitee.com/yangshangwei/gitProject.git (push)

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ git remote add test  https://gitee.com/yangshagnwei/test.git #添加远程地址

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ git remote -v  #添加远程地址
origin  https://gitee.com/yangshangwei/gitProject.git (fetch)
origin  https://gitee.com/yangshangwei/gitProject.git (push)
test    https://gitee.com/yangshagnwei/test.git (fetch)
test    https://gitee.com/yangshagnwei/test.git (push)

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ git remote remove test  #删除远程地址

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ git remote -v  #查看远程配置 
origin  https://gitee.com/yangshangwei/gitProject.git (fetch)
origin  https://gitee.com/yangshangwei/gitProject.git (push)

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$

在这里插入图片描述


多个远程仓库演示

第一个仓库


artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ git remote -vv   # 查看远程配置 
origin  https://gitee.com/yangshangwei/gitProject.git (fetch)
origin  https://gitee.com/yangshangwei/gitProject.git (push)

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ mkdir -p src/main/java/com/artisan # 新建目录 

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ echo 'package com.artisan' > src/main/java/com/artisan/Hello.java  # 创建文件

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ git status   # 查看本地状态 
On branch master
Your branch is up to date with 'origin/master'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        src/

nothing added to commit but untracked files present (use "git add" to track)



artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ git add -A ;git commit -am '7 commit' ; git push  #  local cache --> local repositroy ----> remote repository
warning: LF will be replaced by CRLF in src/main/java/com/artisan/Hello.java.
The file will have its original line endings in your working directory
[master b685db4] 7 commit
 1 file changed, 1 insertion(+)
 create mode 100644 src/main/java/com/artisan/Hello.java
Enumerating objects: 9, done.
Counting objects: 100% (9/9), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (8/8), 502 bytes | 502.00 KiB/s, done.
Total 8 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/yangshangwei/gitProject.git
   9f302ff..b685db4  master -> master

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ git branch -avv  # 查看分支映射 master -----------> origin/master 
* master                b685db4 [origin/master] 7 commit
  remotes/origin/master b685db4 7 commit

好了,提交到 https://gitee.com/yangshangwei/gitProject.git 分支了,我们去gitee上查看一把

在这里插入图片描述


第二个仓库

新建 仓库 gitProject2

首先我们先新建个仓库 gitProject2

在这里插入图片描述
在这里插入图片描述


上传至远程新仓库


artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ git remote add origin2 https://gitee.com/yangshangwei/gitProject2.git  # 添加远程仓库 gitProject2

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ git remote  # 查看
origin
origin2

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ git remote -vv # 查看详情
origin  https://gitee.com/yangshangwei/gitProject.git (fetch)
origin  https://gitee.com/yangshangwei/gitProject.git (push)
origin2 https://gitee.com/yangshangwei/gitProject2.git (fetch)
origin2 https://gitee.com/yangshangwei/gitProject2.git (push)

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ git push  --set-upstream origin2 master   #  上传新分支至远程
Enumerating objects: 20, done.
Counting objects: 100% (20/20), done.
Delta compression using up to 12 threads
Compressing objects: 100% (8/8), done.
Writing objects: 100% (20/20), 1.46 KiB | 749.00 KiB/s, done.
Total 20 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/yangshangwei/gitProject2.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin2'.

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$
 

执行完 git push --set-upstream origin2 master 后 ,后面再 git push 其实是上传到了 origin2 分支,可以看下

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ git branch -avv
* master                 b685db4 [origin2/master] 7 commit
  remotes/origin/master  b685db4 7 commit
  remotes/origin2/master b685db4 7 commit

可以发下 master 对应的分支 为 origin2/master 。

orgin2 对应了我们的 git remote add origin2 https://gitee.com/yangshangwei/gitProject2.git gitProject2 项目 。

我们来验证下

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ pwd
/d/opt/gitdemo/gitProject

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ echo 'artisan git git git ' > README.MF

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ git push
Everything up-to-date

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ git status
On branch master
Your branch is up to date with 'origin2/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   README.MF

no changes added to commit (use "git add" and/or "git commit -a")

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ git add -A ;
warning: LF will be replaced by CRLF in README.MF.
The file will have its original line endings in your working directory

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ git commit -am '8 commit';
[master 36a0f02] 8 commit
 1 file changed, 1 insertion(+), 4 deletions(-)

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 284 bytes | 284.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/yangshangwei/gitProject2.git
   b685db4..36a0f02  master -> master

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$

在这里插入图片描述


上传至远程原仓库

那如果要 push 到 原来的 origin 这个远程地址呢 ,执行 git push origin 指定分支名即可。

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$ git push origin
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 284 bytes | 284.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/yangshangwei/gitProject.git
   b685db4..36a0f02  master -> master

artisan@LAPTOP-JF3RBRRJ MINGW64 /d/opt/gitdemo/gitProject (master)
$

在这里插入图片描述

当然了在IDEA中的操作就简单了

在这里插入图片描述

选择就可以了。
在这里插入图片描述

  开发工具 最新文章
Postman接口测试之Mock快速入门
ASCII码空格替换查表_最全ASCII码对照表0-2
如何使用 ssh 建立 socks 代理
Typora配合PicGo阿里云图床配置
SoapUI、Jmeter、Postman三种接口测试工具的
github用相对路径显示图片_GitHub 中 readm
Windows编译g2o及其g2o viewer
解决jupyter notebook无法连接/ jupyter连接
Git恢复到之前版本
VScode常用快捷键
上一篇文章      下一篇文章      查看所有文章
加:2022-08-19 19:26:35  更:2022-08-19 19:27:00 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/25 22:41:22-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码