Day 88/100 如何把Git仓库代码推送到另一个新的Git仓库中

2年前 (2022) 程序员胖胖胖虎阿
251 0 0

(一)需求

需要把旧代码库中的指定分支,推送到新的Git仓库中。

(二)步骤

1、建立新的Git仓库

2、切换本地的代码仓库为新的Git仓库地址

# 更换remote
git remote set-url origin http://***.git
git remote set-url origin --push http://***.git

3、新建SSH证书添加到远程新的Git仓库所在的SSH认证代码库中

ssh-keygen -t rsa -C "email"
cat id_dev_rsa.pub 
# 复制生成的公钥到Git仓库的SSH账号中新增

# 可能会遇到没有权限的问题,需要设置全局密码
cd ~/.ssh/ 
git config --list
git config --global user.name "name"  
git config --global user.password "password"
git config --global user.email "email"

4、推送当前分支代码

// 推送代码
git push

5、切换本地分支,继续推送分支代码

// 推送代码
git checkout <分支名>

(三)附:

其他常用Git命令

# 分支重命名
git branch -m old_name new_name
# 重命名后推送到远程
git push origin new_name
# 删除远程旧分支
git push origin --delete old_name

# git合并远程分支
git pull origin branch_name
# git合并本地分支
git merge branch_name
# git放弃/终止合并
git merge --abort

最后

我发起了前端共读会,感兴趣的伙伴可以一起来读(ardenzhaogx)

相关文章

暂无评论

暂无评论...