Git - 入门到熟悉_远程仓库管理

简介: Git - 入门到熟悉_远程仓库管理

549742b71b7c4e33a0be7e3791127049.png

Pre

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

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


常用命令


164dcb19595e455e88bdbbeec2ec9c79.png

#查看远程配置 
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上查看一把

26fabde4f10b4b63bba2406516847ea4.png


第二个仓库

新建 仓库 gitProject2


首先我们先新建个仓库 gitProject2


df0671b0c4af4da898b56f8341400f76.png


21239840d5ec49fe9e443df1505eab45.png


上传至远程新仓库

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)
$

f74684432fe9483190e6cd22e3ebe703.png

上传至远程原仓库


那如果要 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)
$


e5b7686f4cb04d1dbb7013f755e8d6d6.png

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


80f28bed5167438d8513093b1f6eef4b.png


选择就可以了。

相关文章
|
1月前
|
Linux 开发工具 git
【Git】Git 完全指南:从入门到精通
Git 是一种强大的版本控制工具,掌握了其基本命令和高级特性后,可以大大提高开发效率并方便团队协作。通过本篇文章,你已经学会了 Git 的核心命令及其使用方法,希望你能够灵活运用 Git 在实际项目中进行版本管理。
91 4
|
2月前
|
缓存 Java Shell
[Git]入门及其常用命令
本文介绍了 Git 的基本概念和常用命令,包括配置、分支管理、日志查看、版本回退等。特别讲解了如何部分拉取代码、暂存代码、删除日志等特殊需求的操作。通过实例和图解,帮助读者更好地理解和使用 Git。文章强调了 Git 的细节和注意事项,适合初学者和有一定基础的开发者参考。
60 1
[Git]入门及其常用命令
|
7月前
|
持续交付 项目管理 开发工具
Git项目管理——远程仓库(四)
Git项目管理——远程仓库(四)
81 2
|
6月前
|
网络安全 开发工具 数据安全/隐私保护
Git远程仓库Gitee的使用详解
Git远程仓库Gitee的使用详解
Git远程仓库Gitee的使用详解
|
6月前
|
开发工具 git
git或gitee 提交代码到远程仓库
git或gitee 提交代码到远程仓库
67 2
|
5月前
|
存储 Shell 开发工具
Git 入门:从零开始掌握版本控制的艺术
【8月更文第16天】 在软件开发中,版本控制是一项至关重要的技能。它帮助开发者追踪文件的变化历史,并且可以在多个开发者之间协同工作。Git 是目前最流行的分布式版本控制系统之一。本文将带你从零开始学习 Git 的基本使用方法。
67 0
|
6月前
|
存储 开发工具 git
好的git管理方法,标明项目_编号_(功能,不过还是在没有bug出现时就提交为好)+Excel表管理的格式
好的git管理方法,标明项目_编号_(功能,不过还是在没有bug出现时就提交为好)+Excel表管理的格式
|
7月前
|
网络安全 开发工具 git
git项目提交到远程仓库
git项目提交到远程仓库
|
6月前
|
数据可视化 程序员 开发工具
小白也能玩转Git:从入门到实战详细教程
小白也能玩转Git:从入门到实战详细教程
|
7月前
|
开发工具 git
大事件项目66-----项目中git的管理使用
大事件项目66-----项目中git的管理使用