Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe if more git commands are run on the same repo in parallel?

I am interested if it is safe to run things like git push and git commit in parallel (for example in cron jobs, jenkins jobs etc.). Is there some locking mechanism built-in in git so these operations are serialized or this can corrupt the repository?


1 Answers

Yes. Git works by writing references in a manner that allows for this. If you are doing a commit at the same time as a push, push will only go from the references down to the objects they contain. If the commit finishes and updates the branch reference on time, it will get pushed. If it doesn't, the old reference will be pushed. You won't get "half a commit" pushed up.

All files are written in a manner that implicitly preserves referential integrity for any pointers. The last file written will be the reference that already has all it's dependencies there.

like image 74
Adam Dymitruk Avatar answered Sep 12 '25 09:09

Adam Dymitruk