I have an existing local Git repository and would like to add a branch corresponding to a branch on an unrelated remote Git repo (ideally without the full history+), from which I may occasionally pull updates. I've been struggling with how to accomplish this and have come up with
git checkout -b template
git remote add framework <repo_url>
git pull --rebase=true framework template:template --force
and wonder if this is really the best way to go about it.
Is there a more compact or more idiomatic way to add a branch from a new remote to an existing Git project?
+The issue with attempting to get just a partial history (with --depth
as an additional option to the pull
is that it creates a structure that crashes all my Git tools (Tower, GitX, etc.).
Set up the remote with
git remote add -t template -f framework <repo_url>
which will also fetch the ref for just the one branch on the remote; and then checkout the branch into a new local branch using
git checkout -b template framework/template
Now you can pull this branch from your original remote from the local branch using
git pull