git本地分支推送到远程和远程pull到本地

文章目录

本地分支推送到远程仓库

要将本地分支推送到远程仓库的某个分支(可以是同名的分支,也可以是不同名的分支),你可以使用 git push 命令。这里有几种不同的情况:

  • 推送到同名的远程分支
    如果你的本地分支与远程分支同名,且远程分支已经存在,你可以简单地执行
bash 复制代码
git push origin 分支名

其中 origin 是远程仓库的默认名称,分支名 是你的本地分支名。

  • 推送到不同名的远程分支
    如果你想推送本地分支到一个不同名的远程分支(或者远程尚未有这个分支),可以使用以下命令
bash 复制代码
git push origin 本地分支名:远程分支名

如果远程分支不存在,Git 会创建一个新的远程分支。

  • 关联本地分支和远程分支
    如果你想在以后的推送中不再每次都指定远程分支名(即设置默认的上游分支),你可以使用 -u(或 --set-upstream)标志来设置跟踪关系:
bash 复制代码
git push -u origin 本地分支名

或者

bash 复制代码
git push --set-upstream origin 本地分支名:远程分支名

设置跟踪关系之后,下次你只需调用 git push 即可将更改推送到关联的远程分支。

强制推送: 如果你需要覆盖远程分支(这很危险,因为它会丢失远程分支上的更改!),可以使用 -f--force 标志:

bash 复制代码
git push -f origin 本地分支名:远程分支名

但是,请只在真正必要且明确了解后果的情况下使用强制推送。

  • 删除远程分支

要删除远程分支,可以用以下命令:

bash 复制代码
git push --delete origin 远程分支名

在执行 git push 之前,确保你已经使用 git add . 将你的改动添加到暂存区,并且使用 git commit 提交了你的更改。在推送到远程仓库之前,你也可能想要先执行 git fetchgit pull 以确保你的本地分支是最新的。

bash 复制代码
PS C:\Users\lenovo> cd F:\infinite_waves\doraemon
* master
PS F:\infinite_waves\doraemon> git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/aws_deploy
  remotes/origin/customer_service
  remotes/origin/develop
  remotes/origin/feature/aws_upload
  remotes/origin/feature/develop_backup
  remotes/origin/feature/image_duplicate
  remotes/origin/feature/pic_progress
  remotes/origin/github_action
  remotes/origin/master
  remotes/origin/pages
  remotes/origin/pinia
  remotes/origin/product
  remotes/origin/test
  remotes/origin/toolapp
  remotes/origin/utm_tool
  remotes/origin/utm_update
  remotes/origin/zj_develop
remote:
To github.com:infwavescode/doraemon.git
 * [new branch]        master -> photo_round
PS F:\infinite_waves\doraemon> git status
On branch master
Your branch is up to date with 'origin/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:   src/api/archives.js
        modified:   src/router/modules/archives.js
        modified:   src/views/Archives/ProductAttr/components/editDiaolog.vue
        modified:   src/views/Archives/ProductAttr/index.vue
        modified:   src/views/Archives/ProductClassify/components/editProductDialog.vue
        modified:   src/views/Archives/SupplierArchives/index.vue
        modified:   src/views/selection/SelectionListNew/components/DecorationDialog.vue

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

no changes added to commit (use "git add" and/or "git commit -a")
PS F:\infinite_waves\doraemon> git pull
Already up to date.
PS F:\infinite_waves\doraemon> git add src/views/Archives/PhotoRound/
PS F:\infinite_waves\doraemon> git add src/views/Archives/PhotoSetting/
PS F:\infinite_waves\doraemon> git add src/api/archives.js
PS F:\infinite_waves\doraemon> git add  src/router/modules/archives.js
PS F:\infinite_waves\doraemon> git commit -m "新增摄影场次及配置信息"
[master c14a211c] 新增摄影场次及配置信息
 6 files changed, 799 insertions(+)
 create mode 100644 src/views/Archives/PhotoRound/components/editPhotoDialog.vue
 create mode 100644 src/views/Archives/PhotoRound/index.vue
 create mode 100644 src/views/Archives/PhotoSetting/components/editPhotoDialog.vue
 create mode 100644 src/views/Archives/PhotoSetting/index.vue
PS F:\infinite_waves\doraemon> git push origin master:photo_round
Enumerating objects: 27, done.
Counting objects: 100% (27/27), done.
Delta compression using up to 8 threads
Compressing objects: 100% (16/16), done.
Writing objects: 100% (18/18), 8.20 KiB | 2.73 MiB/s, done.
Total 18 (delta 10), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (10/10), completed with 9 local objects.
To github.com:infwavescode/doraemon.git
   3a68c7c7..c14a211c  master -> photo_round
git拉取远程分支到本地
  • 查看本地修改状态(未commit的修改)
bash 复制代码
git status
  • 查看本地分支
bash 复制代码
git branch
  • 提交本地修改到本地仓库
bash 复制代码
git add .
git commit -m "新增修改"
  • 推送本地修改到远程仓库
bash 复制代码
git pull origin photo_round
bash 复制代码
(python_env) $ git status
On branch photo_round
Your branch is up to date with 'origin/photo_round'.

nothing to commit, working tree clean
(python_env) $ git branch
* photo_round
(python_env) $ git pull origin photo_round
remote: Enumerating objects: 27, done.
remote: Counting objects: 100% (27/27), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 18 (delta 10), reused 18 (delta 10), pack-reused 0 (from 0)
Unpacking objects: 100% (18/18), 8.18 KiB | 1.36 MiB/s, done.
From github.com:infwavescode/doraemon
 * branch              photo_round -> FETCH_HEAD
   3a68c7c7..c14a211c  photo_round -> origin/photo_round
Updating 3a68c7c7..c14a211c
Fast-forward
 src/api/archives.js                                            |  48 ++++++++++++
 src/router/modules/archives.js                                 |  10 +++
 src/views/Archives/PhotoRound/components/editPhotoDialog.vue   | 142 +++++++++++++++++++++++++++++++++
 src/views/Archives/PhotoRound/index.vue                        | 266 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/views/Archives/PhotoSetting/components/editPhotoDialog.vue |  99 +++++++++++++++++++++++
 src/views/Archives/PhotoSetting/index.vue                      | 234 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 799 insertions(+)
 create mode 100644 src/views/Archives/PhotoRound/components/editPhotoDialog.vue
 create mode 100644 src/views/Archives/PhotoRound/index.vue
 create mode 100644 src/views/Archives/PhotoSetting/components/editPhotoDialog.vue
 create mode 100644 src/views/Archives/PhotoSetting/index.vue
(python_env) [shiwenxin@xcwx01 doraemon]$ npm run dev

> [email protected] dev
> vite --mode development --host

sh: line 1: vite: command not found
相关推荐
打码人的日常分享2 分钟前
智慧城市建设方案
大数据·架构·智慧城市·制造
LUCIAZZZ8 分钟前
HikariCP数据库连接池原理解析
java·jvm·数据库·spring·springboot·线程池·连接池
我在北京coding25 分钟前
300道GaussDB(WMS)题目及答案。
数据库·gaussdb
小Tomkk37 分钟前
阿里云 RDS mysql 5.7 怎么 添加白名单 并链接数据库
数据库·mysql·阿里云
abcnull43 分钟前
github开源协议选择
git·github·开源协议
明月醉窗台1 小时前
qt使用笔记二:main.cpp详解
数据库·笔记·qt
沉到海底去吧Go2 小时前
【图片自动识别改名】识别图片中的文字并批量改名的工具,根据文字对图片批量改名,基于QT和腾讯OCR识别的实现方案
数据库·qt·ocr·图片识别自动改名·图片区域识别改名·pdf识别改名
阿里云大数据AI技术2 小时前
ES Serverless 8.17王牌发布:向量检索「火力全开」,智能扩缩「秒级响应」!
大数据·运维·serverless
老纪的技术唠嗑局2 小时前
重剑无锋,大巧不工 —— OceanBase 中的 Nest Loop Join 使用技巧分享
数据库·sql
Mikhail_G3 小时前
Python应用变量与数据类型
大数据·运维·开发语言·python·数据分析