Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge two remote branches in git

Tags:

git

merge

github

EDIT

Let me paraphrase, I would like to merge two git repositories with the same name, but different remote.

That is, I have a repo_name hosted in git, under a branch name of repo_name_a and I added another branch to git under branch name : repo_name_b

Now, to merge those, what can I do ?

like image 952
spartak Avatar asked Nov 30 '22 11:11

spartak


1 Answers

The answer I've given below was to the previous version of the asker's question. Now it seems to be a completely different question. This may not be relevant.

What you've described is basically how git is intended to be used, with additional features/work done in a branch, and then merged back to master when completed/reviewed.

git clone https://github.com/master_repo/master_repo

is the correct command to get a copy of that repo into your local machine. To then make a branch to work off of,

git checkout -b test_repo is also correct.

But then, when working in your new branch, you'll be doing git add <name of file> and git commit when working in that branch, many times, and then when you want to update the remote repository's history of your test branch, you'll do

git push origin test_repo

This means push my stuff to origin in the test_repo branch.

If you are working in a repo all by your lonesome, then you want to merge to master, on your local machine, the easiest thing to do is

git checkout master git merge test_repo

You probably won't end up with merge conflicts, but if you do, you'll resolve them. And then from your local master branch, you can do

git push origin master to update the remote branch.

If you were working on a project with collaborators, instead you'd probably want to use the github website interface to create a "pull request" from the test_repo branch to the master branch. Your collaborators could then review your changes and suggest improvements and ultimately be in charge of merging your branch into master.

You can also do this if you're working on something yourself. Create a pull request with a high level description of what changes you are asking to have pulled back into master, and then you can merge the pull request into master on the web interface. This is a little bit of a safer, better method because it is eventually how you'll want to use git for collaboratively working on projects, and it leaves a nice descriptive history of what all the merges to master accomplished.

If you choose to do this, then once a branch is merged, you can delete it remotely and run git remote prune origin locally to delete your local branch (and all local branches that have been deleted remotely.)

like image 72
akgill Avatar answered Dec 04 '22 06:12

akgill