How to make the second [git] command execute only after the first command is successful?

For example, I want to synchronize git with just one click

Execute the git commit all first, and immediately execute the git push after this success

What plugins are suitable for use? I looked at the commander and it seems that I cannot determine when the first command will be executed

1 Like

Obsidian Git (plugin) is integrated into Obsidian (limitations exist on mobile).
Otherwise what you need is command line stuff, for outside of Obsidian use.
A shell script that runs regardless of whether Obsidian is running or not.
But as far as I know you don’t need to add an if clause in these sort of cases because the git push is only executed once the add+commit commands have run.

As for Commander, I’m not sure it can run Git plugin commands but possible. Otherwise – depending on the size of the vault and the platform you are on – you can add a wait period of 5000 ms between commands.
But from my experience with Commander macros, there are indeed timing issues so I’d go with non-Commander solution.

I am unable to find any git commands in the original obsidian. Is it because I am missing some settings? Regarding the command line, do you mean that I should use shell to complete one click commit outside of obsidian?

Obsidian doesn’t have a git command. If you have the third party Git plugin installed, it might give the commands. Ctrl/Command+P and type to find out.

Otherwise, and also because I have a largish vault, I do all git-related stuff outside of Obsidian.
What platforms are you syncing between?

I currently do not have a synchronization requirement, using git is for backup purposes

GitHub desktop is well recommended and can be installed anywhere.
Git tutorials you can find on the forum. Create GH account, create your first repository, clone. You may have done that.

When you are more comfortable with git, you can automate even from a terminal in Obsidian with an alias.

I know how to use git, I am curious about how to automate within Obsidian.

You need to install git on your system and write a script that you can execute from Obsidian and add a hotkey to that.
Shell is usually done for this kind of thing but you would need to install plugins and try what works best.
There are 5-6 plugins that has integration with Obsidian.

Try looking at GitHub - denolehov/obsidian-git: Backup your vault with git plugin, this will provide you with an integrated git environment within Obsidian. It’ll have it caveats on mobile, but they’re clearly documented.

This plugin will give you an opportunity to use git for backup on your desktop, and access to most git commands through (internal/plugin) commands in the command palette of Obsidian.

OP wants one-click solution but Commander I don’t recommend.

Can JavaScript in Templater be used with git commands or only shell is used? Need node.js or something? I’m not sure.

Strange, I’ve heard of this plugin before, but I couldn’t find it in the community plugin list in obsidian. I thought it was renamed or no longer maintained. Why didn’t it appear in the community plugin? Is its name in the list just “Git”? If so, I have already installed it

What are you missing then? Are you on desktop? (I’m currently not, so I can’t fully test it)

If we’re talking javascript and how to wait until the first command is finished, it’ll happen automatically for synchronised commands. If the commands are asynchronous, you’ll need to use await.

If you want to chain multiple calls to Obsidian commands, you could use javascript in some variant, or the QuickAdd plugin, and I think some use Commander (not sure why Gino doesn’t recommend it, and I’ve not used it myself).

Since I do know coding, I’d most likely use pure javascript somehow, but this is just a personal preference.

I’m in windows 10.
I had installed “git” plugin in obsidian, and it works well.
I don’t want commit and wait success message then click push, I want one click or auto commit and push. So I got stuck on how to implement it using the command line or plugin

I know some js, can you tell some step/tip about it?

I then suspect QuickAdd might be the better option for you.

If you find that hard to use, I could write up some stuff later today using javascript, but for most it’ll be cleaner to use QuickAdd.

I will try it, thanks

1 Like

Just one question, though, what do you want to do in addition to the Create backup command? Doesn’t that command both commit and push all changes already? (Given you’ve enabled that option)

Just like I said:

I don’t want commit and wait success message then click push, I want one click or auto commit and push. So I got stuck on how to implement it using the command line or plugin

There is 3 steps to backup my things to github, commit ->wait → push, I want make it one click, I click one button or cmd, then leave it to git.exe
In fact, I don’t really care about this little bit of optimization. I have just been using observer for 3 days and I want to improve my familiarity with observer through these small tasks

I’m feeling a little dumb, and like I’m misunderstanding something, but this is quoted directly from the documentation:

Create Backup: Commits all changes. If “Push on backup” setting is enabled, will also push the commit.

Doesn’t that do all of those operations? What am I missing?

There should be no need to start messing with external shell execution like Gino suggests, since all needed command are available through Obsidian commands. And Templater’s javascript block could be used, but it do set a small limit opposed to QuickAdd since Templater would require an active editor to be able to execute the template.