A workflow with remote branches on git
A git workflow from the early days of git, preserved in ambar
This is the workflow that we are currently using for work with remote branches.
Pushing local branch to remote
git push origin my-branch:refs/heads/my-branch
git config branch.my-branch.remote origin
git config branch.my-branch.merge refs/heads/my-branch
That will create a new branch in the remote repository and the appropriate ref.
Pulling from remote to local branch
Before checking out, we need to fetch the branch, because our repo is not aware of it. Run this to understand what I mean.:
git remote show origin
So… let’s fetch and then we’ll be able to do the checkout.
git fetch
git checkout -b my-branch origin/my-branch
You can add a —track to the last command to set up upstream configuration (see the docs)