Is it possible to commit a file in a git branch with out checking out that branch? If so how?
Essentially I want to be able to save a file in my github pages branch
So long as you don't have anything in your current index that differs from your HEAD that you want to keep you can so something like this. (If you do want to keep your index you could temporarily export the GIT_INDEX_FILE environment variable to point at a temporary file for the duration of these commands.)
# Reset index and HEAD to otherbranch
git reset otherbranch
# make commit for otherbranch
git add file-to-commit
git commit "edited file"
# force recreate otherbranch to here
git branch -f otherbranch
# Go back to where we were before
# (two commits ago, the reset and the commit)
git reset HEAD@{2}
We've never actually checked out otherbranch and our working tree files haven't been touched.