Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to combine git commands atomically (not through shell)?

Tags:

Say, I want to do this:

git checkout featureBranch
git rebase master

If I want to combine the two "shell" commands I can do:

git checkout featureBranch && git rebase master

However, that is not atomic. If the git checkout command fails for some reason, the working directory will not be in the same state as before, nor in the final expected state. Also, other processes, such as my IDE, might be able to see the intermediate state between the two commands.

Does git provide a way to combine two actions atomically?

I don't need complete file-system level atomicity. That is, if the combined action requires 10 files in the working directory to be changed, it is okay if other processes can observe these 10 changes individually.

Edit: The above two commands are just for illustration. Also, it could be 3 or more commands that need to be chained.

like image 418
HRJ Avatar asked Sep 14 '16 12:09

HRJ


People also ask

How do I run multiple git commands at once?

All you have to do is to create a file and add all your commands in the same sequence in which you want to execute. That's it!

How do I commit to git in terminal?

Git commit -m The -m option of commit command lets you to write the commit message on the command line. This command will not prompt the text editor. It will run as follows: $ git commit -m "Commit message."


1 Answers

According to the man git-rebase these commands can be merged:

If <branch> is specified, git rebase will perform an automatic git checkout
<branch> before doing anything else. Otherwise it remains on the current branch.

So you could just run:

git rebase master remoteBranch

However there is no general solution.

like image 63
Hauleth Avatar answered Sep 26 '22 17:09

Hauleth