git本地项目同时推送提交到github和gitee同步

git本地项目同时推送提交到github和gitee同步

同时推送到GitHub和Gitee(码云)可以通过设置多个远程仓库地址来实现。具体步骤如下:

一、分别推送
shell 复制代码
# 初始化仓库
git init

# 添加远程仓库
git remote add gitee git@gitee.com:bealei/test.git

git remote add github git@github.com:bealei/test.git


# 查看仓库
git remote -v


# 删除远程仓库
git remote rm gitee
git remote rm github

# 拉取代码到本地
git pull gitee-typora-theme-bealei master

# 查看文件状态
git status


# 工作区所有新增或修改的文件全部提交到暂存区。
git add .


# 提交暂存区到本地仓库
git commit -m "Initial commit"

# 本地仓库推送到远程仓库
git push gitee 
git push github

第一次推送仓库 加-u

shell 复制代码
git push -u gitee
git push -u github

添加分支分别推送会报错

shell 复制代码
git push -u gitee master
git push -u github main
二、一键推送
shell 复制代码
# 初始化仓库
git init

# 添加远程仓库
git remote add gitee git@gitee.com:bealei/test.git

git remote add github git@github.com:bealei/test.git


# 查看仓库
git remote -v

修改.git/config配置文件

config 复制代码
[core]
	repositoryformatversion = 0
	filemode = false
	bare = false
	logallrefupdates = true
	symlinks = false
	ignorecase = true
[remote "gitee"]
	url = git@gitee.com:bealei/test.git
	fetch = +refs/heads/*:refs/remotes/gitee/*
[remote "github"]
	url = git@github.com:bealei/test.git
	fetch = +refs/heads/*:refs/remotes/github/*
[branch "master"]
	remote = github
	merge = refs/heads/master

新配置文件

config 复制代码
[core]
	repositoryformatversion = 0
	filemode = false
	bare = false
	logallrefupdates = true
	symlinks = false
	ignorecase = true
[remote "origin"]
	url = git@gitee.com:bealei/test.git
	url = git@github.com:bealei/test.git
	fetch = +refs/heads/*:refs/remotes/origin/*

[branch "master"]
	remote = origin
	merge = refs/heads/master

开始推送

shell 复制代码
# 查看仓库
git remote -v


# 工作区所有新增或修改的文件全部提交到暂存区。
git add .


# 提交暂存区到本地仓库
git commit -m "Initial commit"


# 本地仓库推送到远程仓库
git push origin 
三、自定义Git别名

你也可以通过设置一个Git别名来实现这一点,只需运行以下命令:

shell 复制代码
git config --global alias.pushall '!git push gitee && git push github'

之后,使用 git pushall [分支名] 可以实现同时推送。

shell 复制代码
git pushall
相关推荐
Franklin9 小时前
VS 版本更新git安全保护问题的解决
git
我是一只代码狗13 小时前
idea中合并git分支
git
我是一只代码狗13 小时前
idea中使用git
git·gitee·github
恋喵大鲤鱼13 小时前
git restore
git·git restore
李少兄14 小时前
Git Commit Message写错后如何修改?已Push的提交如何安全修复?
git·安全
Fireworkitte14 小时前
git stash
git
产品经理独孤虾15 小时前
GitHub Copilot:产品经理提升工作效率的AI助手
github·copilot·产品经理·原型设计·ai工具·效率提升·prd
杜莱16 小时前
IDEA 安装AI代码助手GitHub Copilot和简单使用体验
人工智能·github·intellij-idea
LogicFlow17 小时前
对单调的画布说拜拜👋🏻
前端框架·开源·github