Reputation: 19069
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?
Upvotes: 6
Views: 630
Reputation: 40971
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
Upvotes: 2
Reputation: 19069
I didn't find any magic one-liner, but doing a git merge
(thanks @Wikiti for inspiring me towards trying that option once again) seemed to work.
The final method I followed is not pretty, and involves running git reset
a number of times.
This is not perfect, and I encourage any git experts or gitlab employees to suggest better solutions. In the hopes it will help others trying to move away from a gh-pages
branch, this is how I did it:
git checkout master
git checkout -b master-docs
git merge gh-pages
# Reset the "master" files so that files deleted are left untouched by the merge
git reset src/
git checkout src/
git reset any-other-master-files
git checkout any-other-master-files
# Manually edit any conflicts, e.g. in .gitignore (with your favourite editor)
vi .gitignore
git add .gitignore
vi any-other-conflicting-files
git add any-other-conflicting-files
# Move the "gh-pages" files into "docs/" directory
mkdir docs
git mv *.md docs/
git mv *.html docs/
git mv _posts docs/
git mv _layout docs/
git mv any-other-gh-pages-files docs/
# Check that everything looks OK, there should be only files added to docs/
# If not, go through last steps again
git status
# Confirm the merge
git commit
# Push to origin
git push -u master-docs
# Go to github, make a pull req from master-docs to master for peer review
(The result doesn't look bad )
Upvotes: 0
Reputation: 1636
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
Upvotes: 1