1

I have a git repo in my computer and one of the directories inside this repo is a git worktree that holds the html build of the docs. So the tree goes something like this

. # <--- main branches here!
├── docs
│   └── _build
│       ├── doctrees
│       ├── html # <--- gh-pages branch here!
│       │   ├── _modules
│       │   ├── _sources
│       │   └── _static
│       └── latex
├── examples
└── mypackage
    ├── subpackages
    └── subpackages

When I work at the docs, both branches (dev and gh-pages) get updated, because I change the files in the docs directory and then sphinx compiles the html into the html directory.

However, when I'm done with the process, I have to manually perform git add . && git commit in both the main branch and the gh-pages branch, to then push all changes to git.

This is not awfully troublesome, but it would be handy if I could issue one command for all branches. I know that git push can be "defaulted" to push all branches (which is what I do) but I found no way of doing this to add and commit such as (for example; just for the sake or clarification)

git add . --allbranches
git commit --allbranches -m "updated the docs"
git push

or something like that. Is there a way to do it?

Cheers!

TomCho
  • 3,204
  • 6
  • 32
  • 83
  • 1
    You don’t seem to understand what branches in Git are. Branches do not exist at paths. Please [read a book](https://git-scm.com/book/en/v2). – poke Jul 22 '16 at 11:50
  • @poke I know I can change branches within one directory and that a branch doesn't have to exist in a specific directory. I use all my 4 branches in my top directory of all my computers, except `gh-pages`, which I leave permanently checked out in the `html` for practical purposes, which is what I meant. Thanks anyway for the book tip. – TomCho Jul 22 '16 at 16:38
  • you might find [this answer](http://stackoverflow.com/a/16389663/4233593) helpful. – Jeff Puckett Jul 23 '16 at 17:20

2 Answers2

1

It's not possible to commit to multiple branches at one time nor to merge branches not currently checked out.

But you can shorten commands a little bit. To add all changes and make a commit, then push in one line

git commit -am "commit message" && git push
Jeff Puckett
  • 37,464
  • 17
  • 118
  • 167
0

My projects usually have a top-level directory with "development" stuff. So I would probably make a script scripts/build_doc.sh (or whatever language you prefer) like this:

#!/bin/bash

if [ "`git status -z`" != "" ] ; then echo Need clean directory ; exit 1 ; fi

whatever_command_to_rebuild_pages

git add -A dir_to_built_html_pages && \
git commit -m "autobuild" && \
git push 

Two thoughts: 1) you could do this in a commit-hook, 2) are you sure you want to have generated files in your repository, at all?

AnoE
  • 8,048
  • 1
  • 21
  • 36