I was looking for a way to commit to GitHub when I found this post, which proved rather useful. =). I guess my answer is a tad late and only elaborates on the solutions already posted a bit beyond the scope of OP's question. However, the issue I was faced with is that the automated timestamp did not work on Linux (Ubuntu 19.10) with the previously posted solutions. Also, adding the script to "Build & View" will create a LOT of commits if you use it frequently. So, personally I came to the conclusion it works better by adding a button/hotkey in TexStudio that can be used to commit.
I found these tutorials for adding an existing project to GitHub using the command line, and for Overleaf GIT TexStudio integration, which I used to set up TexStudio with GitHub. Anyway, I thought I'd add the steps I went through to set up TexStudio with Git and GitHub, with the addition of a timestamp working correctly with Linux.
- Create a dummy repository on GitHub and find the "Add .gitignore"-button and select "TeX". After creating the repo, download it and copy .gitignore to the folder you want to commit. (This saves you a lot of trouble figuring out which files you need to save and not.)
- Set up your GitHub account for use with SSH, if you haven't already. Now create a new, clean GitHub repository, without any adding a README or .gitingore. (Having files already present in my repo created staging problems when I tried to upload.)
- Follow the instructions to set up your repository with GitHub. Set it up with the SSH-link, as https will create a prompt for username and password every time you try to upload a commit.
- After this is done, the process of uploading a commit can be automated in a script. Open a text editor in terminal in
/usr/local/bin as super user. (
Ctrl+Alt+T to open terminal, then write
sudo gedit /usr/local/bin/gitcommit.sh). Write something along the lines of:
git add .
# Adds all files in the local repository and stages them for commit (except those defined in .gitignore).
git commit -m `date "+%Y-%m-%d_%H:%M:%S_%Z"`
# Commits the tracked changes with the current time in the format "2020-02-15_23:29:56_CET".
git push origin master
# Pushes the changes in your local repository up to the remote repository you specified as the origin
- In TexStudio, under the preferences ("Configure TexStudio", check the Advanced Mode box), in the Build menu add a new user command as in the picture:
- Go to the Toolbars menu. Find your command under "All menus>Tools>User" and add to "Tools". You can also go to shortcuts and find your command there and add a desired keyboard shortcut. (Now, you could choose to add this command to "Build & View" or compiler by adding the command
txs:///gitcommit.sh, like @barghest suggests. However, for me that ended up in an unreasonable amount of commits, so I chose not to.)