I have a Git repo with multiple projects on different branches
I'd like to break these out into different standalone repos. I created new repositories for each already. I'd like to have each branch and all their commits history moved to their new individual repository.
The steps to follow in order to push new Git branches to remote repos such as GitHub, GitLab or Bitbucket are as follows: Clone the remote Git repo locally. Create a new branch with the branch, switch or checkout commands. Perform a git push with the –set-upstream option to set the remote repo for the new branch.
If each branch contains only the corresponding code, then this is pretty simple. It's actually even simpler to just create the new repo with git clone --single-branch --branch <original-repo-url>
, but if you've already init
ed and just want to bring in the history, you could do something like
git fetch <original-repo-url> +frontend:master
You'll get weird behavior if you haven't created the first branch in the new repo - so in that case you'd first just create some dummy commit and then detach from the branch so that the update will go through.
git commit --allow-empty -m temp
git checkout --detach
git fetch <original-repo-url> +frontend:master
git checkout master
On the other hand, if each of your branches contains all of the code, and you want to rewrite the history for each "new" repo to only include the relevant code, then you probably want to use git filter-branch
. It has many options, so without more specific details I can't say exactly what options you'd use, but the subdirectory filter may be of interest.
Docs at https://git-scm.com/docs/git-filter-branch
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With