Copy git tree from one Github repo to another using Trees API

Viewed 278

Say I have two repos, repo1 and repo2.

Let's say repo1 has the following directory structure:

repo1
|--someFolder
   |-- file1.txt
   |-- file2.jpg

And let's say repo2 is empty. My goal is to use the GitHub Trees API to copy all of someFolder into repo2. But I've run into the following problems:

  1. When I use the following parameters in my HTTP POST request to the url https://api.github.com/repos/my-username/repo2/git/trees with the following parameters

    {'base_tree': repo2_base_tree_sha, 'tree': [ //Specially formatted tree from repo1 {'mode': u'100644', 'path': u'.travis.yml', 'sha': u'559d004c3af59b3bd8dcc486d5d2b5f91ab4f85d', 'type': u'blob'}, {'mode': u'100644', 'path': u'README.md', 'sha': u'11e4f5fa0b929ff6bccd8f5bcd99cbdbd845d69a', 'type': u'blob'} ] } I get a 422 response with a message saying tree.sha 559d004c3af59b3bd8dcc486d5d2b5f91ab4f85d is not a valid blob. This leads me to believe that one cannot simply construct a new tree for repo2 using a tree from repo1, so how is one to take a tree from another repository and add it to another?

  2. Secondly I can successfully modify repo1's base tree using the same parameters above except that base_tree is repo1's base_tree SHA. However, when I visit repo1 those changes aren't reflected, not sure as to why.

2 Answers
Related