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
It can be done by reimplementing git commit.
This can be done with various call to git hash-object
But this is hard to achieve.
Please read progit chapter 9 for more details and a full example of how to simulate a commit.
While there is currently no single command to do this, there are at least two other options.
You could use the github api to create the commit. This post details creating a commit in a github repo.
Create github pages as a submodule.
Use a series of plumbing commands to create the commit.
The git book has a description of plumbing commands used to create a commit
note: the command is now mktree not mk-tree
I made a little tool that does exactly this: https://github.com/qwertzguy/git-quick
It let's you edit specific files from another branch without checking out the other branch completely (just the files you want to edit) and commit them. All this without ever affecting your working copy or staging area.
Behind the scenes it uses a combination of git worktree and sparse checkout. The source is fairly small, so you can read through.
No you cannot, however what you are doing by hard copying files is implemented by git stash
using commits. The stash
works as a stack of changes that are saved "somewhere outside the branches spaces", hence can be used to move modifications between branches.
<file>
<file>
<branch you want to commit>
<commit message>
"you can probably scrip these simple commands down if you do this constantly.