Skip to content

Instantly share code, notes, and snippets.

@appleboy
Last active May 18, 2023 07:03
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save appleboy/8092600 to your computer and use it in GitHub Desktop.
Save appleboy/8092600 to your computer and use it in GitHub Desktop.
Copy all branch from another repository?

Repository url

origin: https://github.com/appleboy/git-test
remote: https://github.com/appleboy/html5-template-engine

Copy all branch from another repository

# clone origin repo
$ git clone https://github.com/appleboy/git-test
$ cd git-test
# add remote repo url.
$ git remote add html5 https://github.com/appleboy/html5-template-engine.git

show all remote repo

$ git remote -v
html5   https://github.com/appleboy/html5-template-engine.git (fetch)
html5   https://github.com/appleboy/html5-template-engine.git (push)
origin  git@github.com:appleboy/git-test.git (fetch)
origin  git@github.com:appleboy/git-test.git (push)

fetch remote repo data

$ git fetch html5

show all branch info

$ git branch -a

* master                       420f7f5 update test.php
  remotes/html5/master         b6e0324 update html
  remotes/origin/HEAD          -> origin/master
  remotes/origin/master        420f7f5 update test.php

copy html5/master branch to origin repo

$ git checkout -b html5/develop html5/master

show all branch info

$ git branch -a
* html5/develop                b6e0324 update html
  master                       420f7f5 update test.php
  remotes/html5/master         b6e0324 update html
  remotes/origin/HEAD          -> origin/master
  remotes/origin/develop       206c580 some change edit
  remotes/origin/html5/develop b6e0324 update html
  remotes/origin/master        420f7f5 update test.php

push html5/develop to origin server

$ git push origin html5/develop
@jrayga
Copy link

jrayga commented Sep 25, 2019

Thank you for this. How about if the branch the html5/master branch was updated and I need also need that update to git-test project?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment