Reputation: 13681
I have repository blog
:
blog
├─ master
│ └─ _site
│ └─ more folders
│
└─ gh-pages
I would like to map master:_site/
to the branch gh-pages
. How would I do this using git
?
Upvotes: 1
Views: 2676
Reputation: 137
Go to current directory, which you want to map to remote master, and then type below.
copy ".git" folder from cloned dir to current direcotry
cp yourClonedFolder/.git .
delete clone folder
rm -rf yourClonedFolder
git add .
Upvotes: 0
Reputation: 60313
I believe this is fully paranoid:
#!/bin/sh
if ghpages=`git rev-parse -q --verify gh-pages`; then
# there's already a branch, don't double-commit a tree
committed=`git rev-parse -q --verify gh-pages^{tree}`
current=`git rev-parse -q --verify master:_site`
test x$current = x$committed && exit
fi
if commit=`git commit-tree ${ghpages:+-p $ghpages} -m 'updating gh-pages' master:_site`; then do
git update-ref refs/heads/gh-pages $commit
fi
To hardwire the mapping as requested, put that in .git/hooks/post-commit
and chmod +x
it.
Upvotes: 2
Reputation: 13681
One way to do this is to initialize a git repository in _site
.
cd blog
# populates _site
jekyll build
cd _site
# create git repository, add files and push
git init
git checkout -b gh-pages
git commit -am "message"
git remote add [email protected]:<user>/<repo>.git
git push origin gh-pages
Upvotes: 0
Reputation: 7305
From the wide variety of intimidating ways to perform this, I'd secretly (?) do this one for me (starting from the root of the local copy in the branch master):
git checkout gh-pages
git checkout master -- _site/
mv _site/* .
rm -rf _site
Then commit and push changes:
git add .
git commit -m "Copied site from master"
git push origin gh-pages
Upvotes: 1
Reputation: 311740
You can add the gh-pages
branch to the primary repository as a submodule. Something like this:
cd blog
git submodule add -b gh-pages <my-repository-url> master/_site
This assumes that the directory master/_site
does not already exist. You will want to thoroughly read and understand the submodules section of the Git book. In particular, when you commit changes inside of your _site
directory, the process will generally be:
cd master/_site
...edit some file...
git add some_file
git commit -m 'edit all the things'
cd ..
git commit -m 'edited some files' _site
Upvotes: 2