If you want to pull
a branch in a remote repository, into your current branch, you do not need to switch.
If I understand correctly, you have one repo with release
checked out, and another with dev
checked out, in which you are working. When you're done with something in dev
, you want to merge it in release
, without a checkout of release
.
I suppose that you have remotes setup in both repos, so that both can refer to each other.
cd
to your release
repo. Fetch the changes from the dev
repo:
git fetch <dev_remote> <branch>
You now have an updated dev
branch in your release
repo, although you did not need to check it out. Note however that the name of the updated dev
branch contains: the name of the remote, a slash, then the name of the branch. It's a remote branch, it shows in two colors in gitk
, and as remotes/<remote_name>/<branch>
with git branch -a
.
Merge the updated branch to your local release
branch:
git merge <dev_remote>/<branch>
And there you have it. No checkout
, but your release
branch in your release
repo has merged the content of dev
.
This is for the principle. Now you can do this in one step instead:
cd <release_repo> # you are on the release branch
git pull <dev_remote> <branch_name_in_dev_remote>
Your branch in dev_remote
will be fetched, and merged into your currently checked out branch in the release
repo.
Likewise, you'll want to update your dev
repo with the new merge commit in release
:
cd <dev_repo> # you are on the dev branch
git pull <release_remote> <branch_name_to_pull>