Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: How to move contents of gh-pages branch to docs/ directory preserving history?

So github recently implemented a feature to use the docs/ directory of master instead of gh-pages. And this is good for some use cases, such as mine.

The scenario is a git repo with a master and a gh-pages branch (the "old" way of doing github pages), and I want to move everything in the gh-pages branch to the docs/ directory in master (the "new" way of doing github pages).

I'm aware I can use git checkout master; git checkout gh-pages -- docs, but this will remove history from the gh-pages files, which is undesired.

I have fiddled around with git subtree and git filter-branch, with no success.

So the question is: Is there a magic one-liner git command to move the contents of another branch into a subdirectory while keeping history?

like image 928
IvanSanchez Avatar asked Oct 18 '22 03:10

IvanSanchez


2 Answers

git subtrees are perfect for this. You mentioned you "fiddled" with them, but did you try:

git subtree add --prefix=docs origin gh-pages

Check out my docs-subtree branch

like image 52
Jeff Puckett Avatar answered Oct 31 '22 13:10

Jeff Puckett


I don't know if there is a one-line command, but you could try a rebase, and then merge it into master:

git checkout gh-pages
git rebase master
git checkout master
git merge --no-ff gh-pages
like image 44
Wikiti Avatar answered Oct 31 '22 12:10

Wikiti