Let’s assume I have a git repository in /Users/leec/test/gitpublish/test3 that already has at least one commit in it (so it contains at least one valid branch). Let’s create a “remote tracking branch” off of our current branch (e.g. master) that will manage my WordPress blog.
Starting in my git repo directory, on my master branch, I create a new remote tracking branch:
$ gitpub.py remote add ie wordpress:cjlee112@infoevolution.wordpress.com
Switched to branch 'gpremotes/ie/master'
[gpremotes/ie/master 70313f9] create new tracking branch
2 files changed, 18 insertions(+), 0 deletions(-)
create mode 100644 .gitpub/ie.json
create mode 100644 .gitpub/ie.lastpush.json
A few notes:
The only difference vs. the instructions above is the format for specifying your Blogger blog (replace ie with whatever you want the gitpublish branch name for this blog to be):
$ gitpub.py remote add ie blogger:blogger:user=your_email@gmail.com:blog_id=YOUR_BLOG_ID
where you substitute your own gmail address and blog ID above. (You can get the blog ID by going to the Settings of your Blogger blog, and looking at the URL that your browser displays).
Next, let’s tell Gitpublish that we want to publish an existing restructured text file to our remote server, as a new blog entry with an associated image file:
$ gitpub.py add index.rst summer_tanager_3_B.jpg
$ gitpub.py commit -m 'added two files'
[gpremotes/ie/master e9b7503] add two files
1 files changed, 8 insertions(+), 1 deletions(-)
This does several things:
The two files are “staged” for being pushed to the remote server, by being added to your local-to-remote document mapping, with an annotation that they don’t yet have a corresponding document on the remote repository.
The commit saves this “staging information” to your git branch gpremotes/ie/master so you can use all the power of git to manage this information in the future. Specifically, they are registered in the .gitpub/ie.json file mentioned above.
Note that by default restructuredText files are added as posts, and image files as images to the WP media library (which can be referenced by your posts / pages). To add a document as a page instead of a post, simply add the following --docarg command line option:
$ gitpub.py --docarg pubtype=page add mypage.rst
Finally we push our branch to the wordpress blog:
$ gitpub.py push
Already up-to-date.
[gpremotes/ie/master 2cf39fc] updated gpremotes/ie/master docmap from master
1 files changed, 2 insertions(+), 0 deletions(-)
Enter password for cjlee112 on infoevolution.wordpress.com:
[gpremotes/ie/master e41d69e] publish doc changes to remote ie
2 files changed, 52 insertions(+), 5 deletions(-)
Say I come back to my git repository in the future, after having made changes to index.rst on the master branch. I want to use Gitpublish to push these changes automatically to my WordPress blog. Within my repository directory, I checkout my gitpublish tracking branch, merge and push the latest changes:
$ gitpub.py checkout ie
Switched to branch 'gpremotes/ie/master'
$ gitpub.py merge
Merge made by recursive.
index.rst | 2 +-
2 files changed, 6 insertions(+), 1 deletions(-)
[gpremotes/ie/master ebbede7] updated gpremotes/ie/master docmap from master
1 files changed, 5 insertions(+), 5 deletions(-)
$ gitpub.py push
Already up-to-date.
Enter password for cjlee112 on infoevolution.wordpress.com:
[gpremotes/ie/master 974a224] publish doc changes to remote ie
2 files changed, 15 insertions(+), 15 deletions(-)
A few notes:
If you want to rename a local file that you’ve already published to a remote using Gitpublish, you need to tell Gitpublish where you’re moving it to. You just use the standard git mv syntax:
$ git checkout master
$ gitpub.py mv index.rst mypost.rst
$ git commit -m 'renamed index.rst'
[master 98e0f36] renamed index.rst
2 files changed, 5 insertions(+), 0 deletions(-)
create mode 100644 .gitpub/_git_moves.json
rename index.rst => mypost.rst (100%)
We can now continue making modifications to our new file name:
$ git add mypost.rst
$ git commit -m 'minor change'
[master e7e31f1] minor change
1 files changed, 1 insertions(+), 1 deletions(-)
The next time you run Gitpublish merge in your remote tracking branch, all these changes will be propagated automatically:
$ gitpub.py checkout ie
Switched to branch 'gpremotes/ie/master'
$ gitpub.py merge
Merge made by recursive.
.gitpub/_git_moves.json | 5 +++++
index.rst => mypost.rst | 2 +-
2 files changed, 6 insertions(+), 1 deletions(-)
create mode 100644 .gitpub/_git_moves.json
rename index.rst => mypost.rst (79%)
[gpremotes/ie/master b39ef75] updated _git_moves_merged.json
1 files changed, 5 insertions(+), 0 deletions(-)
create mode 100644 .gitpub/_git_moves_merged.json
[gpremotes/ie/master 80a19b8] updated gpremotes/ie/master docmap from master
1 files changed, 5 insertions(+), 5 deletions(-)
And we can then just push as usual:
$ gitpub.py push
Already up-to-date.
Enter password for cjlee112 on infoevolution.wordpress.com:
[gpremotes/ie/master d6ca583] publish doc changes to remote ie
2 files changed, 15 insertions(+), 15 deletions(-)