How to Use Git with TexStudio

TexStudio is our favorite TeX editor. It works with only SVN version system. Nevertheless, using macroses one can teach it to work with Git also. To do it, one needs to create three new scripts Macros -> Add/Change in the file menu.

Get from server

buildManager.runCommand("git pull ", editor.fileName())


dialog = new UniversalInputDialog() 
dialog.setWindowTitle("Git commit / push") 
dialog.add("Commited by Olek P", "Comment", "comment") 
if (dialog.exec() != null) {
     comment = dialog.get("comment")
     buildManager.runCommand("git commit -a -m \"" + comment + "\"", editor.fileName())

Upload to server

buildManager.runCommand("git push origin master", editor.fileName())

Windows users must change path to git. For example the last script should look like following:

buildManager.runCommand("\"C:\\Program Files\\Git\\bin\\git.exe\" push origin master", editor.fileName())


UPD 21/12/2017

Show git log

buildManager.runCommand("", editor.fileName())

Here script is the following:

FNAME='log.log' # temporary file
TEXTED='kwrite' # default text editor

git log --pretty=format:'%h : %s | Time: %cd' --graph > ${FNAME} && ${TEXTED} ${FNAME}

Compare two commits:

dialog = new UniversalInputDialog()
dialog.setWindowTitle("Choose commit:")
dialog.add("HEAD", "Recent version", "commit1")
dialog.add("HEAD^", "Elder version", "commit2")
if (dialog.exec() != null) {
commit1 = dialog.get("commit1")
commit2 = dialog.get("commit2")
buildManager.runCommand("git difftool " + commit1 + " " + commit2 + " --no-prompt ", editor.fileName())


Leave a Reply