Developers work with many branches at the same time because during any single day they review others' pull requests, try new crazy things, work on new features/bug-fixes and also fix somebody else's PRs. All this forces a combination of git stash [pop|save]
, git fetch
, git checkout [-f]
and again git stash [pop|apply]
. No matter if this is done by command line or with a tool the problem of having only one copy of the code is an ugly constrain.
First clone your existing repository as a bare repo (a repository without files) and do it in a .git
directory.
$ git clone --bare [email protected]:zkSNACKs/WalletWasabi.git .git
There are two non-mutually exclusive alternatives here. One is to work with the other developers' repositories directy or work with the origin
repository only.
Having the team members' repositories as remote makes the work easier:
$ git remote add dan [email protected]:danwalmsley/WalletWasabi.git
$ git remote add jmacato [email protected]:jmacato/WalletWasabi.git
$ git remote add kiminuo [email protected]:kiminuo/WalletWasabi.git
$ git remote add max [email protected]:MaxHillebrand/WalletWasabi.git
$ git remote add molnard [email protected]:molnard/WalletWasabi.git
$ git remote add nopara73 [email protected]:nopara73/WalletWasabi.git
$ git remote add yahia [email protected]:yahiheb/WalletWasabi.git
$ git remote add yuval [email protected]:nothingmuch/WalletWasabi.git
Once we have all the remote repositories we fetch them all (this can be a bit slow but it takes time only the first time)
$ git fetch --all
After that we have absolutely everything locally.
Edit the .git/config file and add this line in the origin
repository section
fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
Once we have this fetch the repo:
$ git fetch origin
The suggestion is to have our master branch in its own folder.
$ git worktree add master
For each team member we can have a dedicated folder in the team folder and then, imagine you need to review two PRs, one from Yahia
and other from Kiminuo
, depending on how you decided to config your repositories it is enough to do:
With developers remote repositories:
$ git worktree add kiminuo/pr-1234 kiminuo/feature/2021-01-Tor-exceptions-2nd
$ git worktree add yahia/pr-2534 yahia/bitcoind-tor-hashes
With origin only remote repository:
$ git worktree add kiminuo/pr-1234 origin/pr/1234
$ git worktree add yahia/pr-2534 origin/pr/2534
Bellow you can see what you got after the previous commands. In this way it is possible to simply switch from PR to PR and from branch to branch as easy as simply cd
.
We can go to the Kiminuo's tor-exceptions branch and work there, add files, review the changes, compile it and test it and we can immediately jump to the Yahia's bitcoind-tor-hashes branch, perform a git pull
to have the latest changes and review it.
├── master
│ ├── WalletWasabi
│ ├── WalletWasabi.Backend
│ ├── WalletWasabi.Documentation
│ ├── WalletWasabi.Fluent
│ ├── WalletWasabi.Fluent.Desktop
│ ├── WalletWasabi.Fluent.Generators
│ ├── WalletWasabi.Gui
│ ├── WalletWasabi.Packager
│ ├── WalletWasabi.Tests
│ └── WalletWasabi.WindowsInstaller
└── pr
├── kiminuo
│ └── pr-1234
│ ├── WalletWasabi
│ ├── WalletWasabi.Backend
│ ├── WalletWasabi.Documentation
│ ├── WalletWasabi.Fluent
│ ├── WalletWasabi.Fluent.Desktop
│ ├── WalletWasabi.Fluent.Generators
│ ├── WalletWasabi.Gui
│ ├── WalletWasabi.Packager
│ ├── WalletWasabi.Tests
│ └── WalletWasabi.WindowsInstaller
└── yahia
└── pr-2534
├── team
├── WalletWasabi
├── WalletWasabi.Backend
├── WalletWasabi.Documentation
├── WalletWasabi.Fluent
├── WalletWasabi.Fluent.Desktop
├── WalletWasabi.Fluent.Generators
├── WalletWasabi.Gui
├── WalletWasabi.Packager
├── WalletWasabi.Tests
└── WalletWasabi.WindowsInstaller
This is also useful for testing bugs in released versions. Imagine you are working in the middle of some refactoring for a new feature and someone reports a bug in v1.1.12.2
. In that case you don't need to stash nor commit anything, instead you can simply do:
$ git worktree add releases/v1.1.12.2 v1.1.12.2
$ cd releases/v1.1.12.2