How to: Work with branches in Access
Pull the work of others, switch to another branch or start a new one, while the database stays open in Access and no code is lost.
Context / problem statement
Code you change in Access lives in the database. git sees it only after an export has written it into the sources. A
git switch or git pull in a terminal therefore works on sources that may be older than the database: a module
changed in Access stays behind on the old branch, or the next export overwrites what the pull brought.
Solution overview
The SDK runs the branch steps through the same check as wkl-office changes:
| Step | What the SDK does first and afterwards |
|---|---|
| Pull | Merges the remote branch into the sources (always a merge, never a rebase) and imports the objects that came in into the open database. An object that you also changed in Access is not imported: it waits for your decision in Changes. A file git could not merge waits as a merge conflict. |
| Pull and push | Like Pull, then pushes the branch when nothing waits for a decision. |
| Fetch | Gets the state of the remote, so the branch shows how many commits there are to pull. Changes nothing in the sources. |
| Switch to a branch | Exports first what you changed in Access and asks before it does; refuses while something waits for a decision. After the switch it offers to import the objects whose sources differ, or to rebuild the database. |
| New branch | Makes a branch from the current state and switches to it; the sources and the database stay as they are, so nothing is checked or exported. |
In the add-in the steps are in the menu Branch of the group Project on the ribbon tab WKL SDK and on the toolbar
WKL SDK of the VBA editor. The menu caption is the current branch, followed by ↑ and the number of commits to push and
↓ and the number of commits to pull, as of the last fetch or pull (main ↑2 ↓1). On the command line the same steps are
wkl-office pull and wkl-office switch.
Implementation
In Access or in the VBA editor:
- Open Branch and choose Pull. The result is in the tab Output. If something waits for a decision, the tab Changes opens.
- To switch, open Branch and choose a branch under Switch to. A branch that exists only on the remote is marked so; switching to it makes a local branch that tracks it.
- If the VBA editor holds code that is not saved, or Access holds changes that are not exported, the add-in asks Export the changes made in Access and switch to branch? Choose Export and switch. The code is saved, the changes are exported, then the branch is switched.
- After the switch, choose Import n object(s) to bring the changed objects into the open database, or Rebuild and reopen to build it anew from the sources of the branch. A rebuild is needed when tables, references or data differ; the question says so.
- New branch… asks for the name. A name that git does not accept or that a branch already has cannot be confirmed.
On the command line:
wkl-office pull Customers.acproj wkl-office pull Customers.acproj --push wkl-office switch Customers.acproj feature/phone --create --export wkl-office switch Customers.acproj main --import
Deciding a conflict after a pull. The tab Changes lists what waits:
- An object changed in Access and by the pull shows Both changed. Keep Access keeps your version, Keep source takes the version of the pull; the step is
wkl-office sync <object> --keep access|sourceon the command line. - A file git could not merge shows Resolve merge conflict. Select it and choose Resolve merge: Keep mine keeps the version of your branch, Take theirs the version of the pull. To merge both by hand, double-click the row: the file opens in Visual Studio Code. Remove the conflict markers, save, and choose Resolve merge again, then Mark as merged. The last file resolved concludes the merge with a commit carrying git's own message. Then import the merged sources with Import changes.
Remarks
- A switch never loses code: work that exists only in Access is exported first, after you agreed. git then takes the changed source files along to the other branch, or refuses the switch when that branch has another version of the same file. Then nothing changes, and you can commit the export first.
- The pull imports only what it brought. An import that was waiting before the pull keeps waiting.
- A pull with a merge conflict of an earlier pull that is not resolved yet is refused.
- The import needs the database of the project open in Access. On the command line without an open database,
switchlists the objects; import them later withwkl-office import --changed, or rebuild. - The SDK starts git without a console. A question git would ask on the console fails at once. Sign-in through a credential helper, such as Git Credential Manager, still opens its own window.
- Only git. In a Subversion working copy the branch menu reads The project is in no git working copy, and
pullandswitchrefuse.