Is it possible to commit a file in a git branch without checking out that branch? If so how?
Essentially I want to be able to save a file in my github pages branch without switching branches all the time. Any thoughts?
I needed to do this atomically without changing the current directory, so multiple commands won't work, even if they can be used as a one liner. Otherwise, you can end up with race conditions.
Update: It's impossible to do what I want (see comments below for use case). I ended up programmatically cloning my current directory to a tmp directory, then checking out my branch in that tmp directory (doesn't affect my working directory) and committing my files to the tmp directory clone. When I'm done, I push back to my working directory and delete the tmp directory. Sucks, but it's the only way to commit files to another branch without changing the current working branch of the working directory. If anyone has a better solution, please feel free to add it below. I'll accept yours if it's better than 'it cannot be done'.
Update update: For full details of why I asked to be able to do this 11 years ago and why I wanted it to be atomic see this repo https://github.com/schneems/git_test. Back in the day we didn't have CI services. Developers at the company I worked for were expected to run tests locally, but not everyone did it. The idea behind that project was to track test run history. This would allow you to see which commit tests (or if they weren't run at all).
CI now handles this functionality but since I asked an "impossible question", I'm always curious if there is an answer.