简体   繁体   中英

git - Merge branch from remoteRepo to local branch

I've been googling for hours, trying to find the way.

I got a repo on gitlab, wish to merge one from github into a branch of mine at my gitlab repo. A way of comitting a merge, or likewise

example:

Merge branch 'Sarah' of https://github.com/repo/server into myServer

where myserver is my branch, sarah is the links branch and the link is a repo

Thank you in advance. PS. I'm noob in this subject, be userfriendly!

Add a remote to your Git Lab repo.

git remote add gitlab https://gitlab.com/user/repo.git
git fetch gitlab

Add a remote to Git Hub

git remote add github https://github.com/user/repo.git
git fetch github

Checkout a new temp branch to merge based on myServer

git checkout -b temp gitlab/myServer

Merge Sarah and resolve conflicts, etc.

git merge github/Sarah

Now you're free to do whatever you'd like with your temp branch. Like push it to Git Lab.

git push gitlab temp

Or if you love it, then you could "overwrite" your myServer branch by forcing the branch name to point to this commit.

git branch -f myServer

And then push that to Git Lab (you may need to force depending on context)

git push gitlab myServer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM