Reputation: 8693
git clone [email protected]:foo/bar.git bar-master
git branch release
git push origin release
git clone -b release [email protected]:foo/bar.git bar-release
cd bar-master
touch foo.txt
git commit -m "foo.txt"
cd bar-release
How do I merge changes from master into bar-release and push back the changes to the remote origin/release branch. What would be the correct way to merge changes and push changes back to the remote branch.
Upvotes: 0
Views: 482
Reputation: 107728
I would really encourage you to get used to working inside the one directory. Git is on-purpose designed for this.
If the reason you're doing this is because you can't immediately tell what branch you're on by using something other than the directory name, then I would encourage looking into things that set your prompt to include the branch name. I have something like this in my personal dot files (bash prompt setting here and __git_ps_1
command here.
This has saved me so many times it's worth its weight in gold.
Now that we've got the multiple directories problem solved, you should read this great post called "A successful Git branching model" that covers using several different branches for development, albeit on a single repository.
Once you're done there, now you're ready to apply this same thing to other repositories. First, you're going to need to add the remote repository to the list of remotes tracked by git. This is just helpful as you can reference by name rather than address, with the name generally being much shorter than the address.
git remote add main [email protected]:organization/main.git
I am going to assume here that the remote is what has this release
branch on it. The first thing you're going to want to do here is update the information about this repository, which you can do with this command:
git fetch main
If you're working with multiple remotes (which would indicate some level of insanity on your part), you can fetch them all with git fetch --all
.
Anyway, once you've done that initial fetch, you can then checkout main
's release
branch into your repository:
git checkout main/release -b release
This tells git, "Hey, get me main/release's branch, and call it release in this repository (please)".
Now, assuming that you've been a good developer, you should be able to directly merge your commits across into this branch from your master
branch. Right now, you'll be in the release
branch that is based off main/release
so you'll just need to do this:
git merge master
Some people here would ask you to rebase
instead (There's an interesting discussion about this here. That has the same syntax as merge: git rebase release
.
Now you need to really really make sure that everything's working as it should. That's up to you.
Once you're super-confident about that, you can push your release
branch to the main
repository by running this command:
git push main release
Now go forth and Git :)
Upvotes: 5
Reputation: 129584
You should be using the same repository with 2 different remotes. You can continue to do this but now you will have to manage pushing and pulling between the 2 local ones as well as the remote.
For you question though, you would push and fetch between the 2 local ones to arrange what you need and then push from either one to the github remote.
Upvotes: 1