2022年2月22日星期二

gitlab github sync

1. add github remote url 
git remote add github https://github.com/repo-name/testscript.git
git remote remove github https://github.com/repo-name/testscript.git

.git/config:
[remote "github"]
url = https://github
.com/repo-name/testscript.git
fetch = +refs/heads/*:refs/remotes/origin/*

2. add gitlab remote url 
git remote add gitlab https://gitlab.com/repo-name/testscript.git

.git/config:
[remote "gitlab"]
url = https://
gitlab.com/repo-name/testscript.git
fetch = +refs/heads/*:refs/remotes/origin/*

3. fetch from github
git fetch github
From https://github.com/repo-name/testscript.git  
 * [new branch]        main          -> github/main    

4. fetch from gitlab
git fetch gitlab
From https://gitlab.com/repo-name/testscript.git  
 * [new branch]        master          -> gitlab/master    

5. push gitlab branch master to github
git push -u github master    #push local branch master to github(remote repo).

ref: https://git-scm.com/book/ja/v2/Git-%E3%81%AE%E5%9F%BA%E6%9C%AC-%E3%83%AA%E3%83%A2%E3%83%BC%E3%83%88%E3%81%A7%E3%81%AE%E4%BD%9C%E6%A5%AD

git branch --set-upstream-to=github/main mbp-main
git fetch mbp-main

-refusing to merge unrelated histories
$ git merge --allow-unrelated-histories target_branch
# コミットを1まとめにしたい場合
$ git merge --allow-unrelated-histories --squash target_branch

reset の取り消し
git reset --soft HEAD@{1}

#when rename remote branch: feature/202203->main, update local branch:
git branch -m feature/202203 main
git fetch github
# set-upstream-to github/main mbp-main
git branch -u github/main mbp-main
#github/HEAD set to main
git remote set-head github -a

没有评论: