Advertisement
Advertisement


Clone some remote branches and push them to a new repository?


Question

I have a master, a development and an experimental branch inside old_repo. How do I clone only master and development inside new_repo? Basically, I want to clone old_repo into new_repo, but without the experimental branch.

2016/06/09
1
4
6/9/2016 2:38:25 PM

Accepted Answer

Clone from old_repo, fetch all other branches (old_repo is URL, origin the resulting alias)

git clone old_repo my_repo
cd my_repo
git fetch

Check out both branches to make sure we have a local ref of them

git checkout master
git checkout development

Add new_repo to remotes (new_repo is URL, new the alias), then only push master and development

git remote add new new_repo
git push new master development
2016/06/09
2
6/9/2016 2:46:30 PM

Create a new empty repository

mkdir new_repo
cd new_repo
git init

Add the new old remote

git remote add old_repo url...

Fetch only the the relevant branches

git fetch old_repo master:refs/heads/master
git fetch old_repo development:refs/heads/development
2016/06/09