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
相关推荐
程序员天天困3 小时前
Loop Engineering 实战:/goal 命令让 AI 自己写完整项目
github
徐小夕3 小时前
我们开源了一款“框架无关”的思维导图编辑器,3分钟集成到任意系统
前端·javascript·github
小爷毛毛_卓寿杰3 小时前
我把 397B 的「Agentic 大脑」塞进了 Xinference,一键部署 Nex-N2
人工智能·架构·github
小爷毛毛_卓寿杰5 小时前
我把一个 3B 模型塞进了 Xinference,然后它干掉了 DeepSeek V3.2
人工智能·开源·github
凌奕5 小时前
别用文档约束你的 Agent:聊聊 Agent 开发流程的思想
llm·github·agent
和你看星星8 小时前
Git rerere:让重复冲突只解决一次
git
HelloGitHub11 小时前
《HelloGitHub》第 123 期
开源·github
逛逛GitHub1 天前
这个 GitHub 有意思啊,Claude Code + Obsidian = 知识库王炸。
github
ZaferLiu1 天前
当Agent需要动手干活:Tool还是MCP?
github
鹏毓网络科技3 天前
Cursor Rules 文件配置实战:3 个隐藏参数让我每月少写 40% 样板代码
前端·github