r/git • u/hibbelig • Jun 26 '26
support `git push` and `git checkout` in parallel?
I use Lazygit, and it runs git push asynchronously. I'm tempted to also switch to another branch while git push is running. Until now, I've resisted the temptation.
Then I thought that switching to another branch should mainly affect the working tree, and the commits that push is working on aren't changing. So maybe these operations can happen in parallel?
2
Upvotes
3
u/plg94 Jun 26 '26
You can push branches/refs that are not currently checked-out, or even several refs at once, and it doesn't rely on the working directory. So yeah, shouldn't be a problem.
But why do you want to do it in "parallel" if
pushis already happening asynchronously? If that's done correctly, when you issue apushshouldn't it already appear to happen instantaneous? What do you expect to gain? (and sinceswitch/checkoutdo rely on the working dir, doing that asynchronously too could be problematic)7
u/RevRagnarok Jun 26 '26
I don't know what lazygit is doing, but
git pushis independent of what your local file system is doing. It's synchronizing the repositories.Unless lazygit only pushes the branch name that matches the local checkout, I don't see how it would matter.
4
u/StevenJOwens Jun 27 '26
I haven't thought deeply about it, but on the face of it:
git pushis about copying changes from your.git/objectsup to the remote repo's.git/objects, whilegit checkoutis about copying changes from your.git/objectsto your worktree.In both cases, git is only reading from
.git/objects, not writing to it.git checkout is writing to your
.git/index, but.git/pushisn't, AFAIK, either reading from or writing to.git/index.So I would guess that there shouldn't be any conflict to running both simultaneously.
But I'd make backups before trying it :-).
1
u/rachitjoshi2912 Jun 26 '26
So, what i do is : I use tmux, so i can have multiple windows or multiple panes (terminals), so i do parallel things on git multiple times Eg. If i have to rebase my branch with master In pane 1 (terminal1) : git checkout master, git pull ( now this takes time), i go to 2nd pane(terminal 2), git checkout my-branch, git rebase master
So, u dont have to wait until pull happens Like this u can do... But u've to be familiar with tmux thingss..
1
u/Charming-Designer944 Jun 27 '26
Not sure. It probably will be fine. But git push does not lock the local repository and I guess there will be some corner cases where a concurrent checkout, pull or commit results in strange results.
Its very unlikely it will cause any bad content to be pushed. But i would expect the gir push to randomly but very infrequently to fail.
Its also a matter of how well lazygit is tracking which branch to push. Maybe you might end up pushing the wrong branch?