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

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

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

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

# 添加远程仓库
git remote add gitee [email protected]:bealei/test.git

git remote add github [email protected]: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 [email protected]:bealei/test.git

git remote add github [email protected]: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 = [email protected]:bealei/test.git
	fetch = +refs/heads/*:refs/remotes/gitee/*
[remote "github"]
	url = [email protected]: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 = [email protected]:bealei/test.git
	url = [email protected]: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
相关推荐
qianmoQ1 小时前
GitHub 趋势日报 (2025年06月04日)
github
Lw老王要学习1 小时前
VScode 使用 git 提交数据到指定库的完整指南
windows·git·vscode
去旅行、在路上1 小时前
Git & Svn
git·svn
abcnull2 小时前
github中main与master,master无法合并到main
git·github
星哥说事3 小时前
使用VuePress2.X构建个人知识博客,并且用个人域名部署到GitHub Pages中
开源·github
勤劳打代码4 小时前
步步为营 —— Github Connection refused 分层诊断
github
寻月隐君5 小时前
深入解析 Rust 的面向对象编程:特性、实现与设计模式
后端·rust·github
养意7 小时前
git提交代码和解决冲突修复bug
git·bug
qianmoQ19 小时前
GitHub 趋势日报 (2025年05月31日)
github
油泼辣子多加20 小时前
2025年06月06日Github流行趋势
github