Brad
Brad

Reputation: 61

Git mirror a repo to specific branch

our company try to fork a github project to our own git server,then we can add our own features on it. We just want to checkout a specific branch, and keep all branches and tags up to this branch, then copy(mirror ?) to our git server.

Upvotes: 5

Views: 25716

Answers (3)

xuhuleon
xuhuleon

Reputation: 31

  1. clone old branch to local
git clone --bare git_url --single-branch --branch  old_branch_name local_dir
  1. change dir
cd local_dir
  1. add new remote
git remote add  new_origin new_git_url 
  1. push to new remote
git push new_origin  old_branch_name 

Upvotes: 3

Jahedul Hoque
Jahedul Hoque

Reputation: 247

Stay on your local original repository and add new repo as your remote

git remote add newRemote NewRepoUrl

Then stay on a specific branch you want to push. Then push the codes to your newrepo that is in your new remote

git push newRemote current_branch_name

Note: newRemote is the remote name where I put my new repo url

Upvotes: 1

stolenmoment
stolenmoment

Reputation: 443

Create the repo on your server. Elsewhere (not in the server repo), clone just the branch with

git clone --single-branch --branch branch_name github_repo_url

Tell git where your repo is:

git remote add mine your_repo_url

Then, push the branch to your repo with:

git push -u mine; git push --tags -u mine

"mine" is the shorthand name of your repo, it could be any string, replacing the default "origin".

This will gather the entire history leading up to branch_name, but no commits that are not ancestral to it.

Upvotes: 9

Related Questions