How do I code against one github repo on 2 computers?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Working against one GitHub repository from two computers is a normal workflow for developers switching between home and office machines. Problems usually come from inconsistent sync habits, not from Git itself. With a repeatable branch routine and frequent pushes, cross-device development stays predictable and low risk.
Initial Setup on Both Computers
Clone the same repository on each machine and configure identity.
If both machines are personal, global config is fine:
Also verify remote URLs match your expected protocol, usually SSH.
Daily Cross-Device Workflow
Use this sequence every time you resume work on another machine:
- sync main branch
- switch to feature branch
- pull latest branch updates
- make small commits
- push frequently
Example:
Then code and commit:
Frequent push operations are your cross-device synchronization mechanism and backup.
Keep Environment Parity Between Machines
Even with identical Git history, development can diverge if toolchains differ.
Keep these aligned:
- runtime versions, such as Python, Node, Java
- dependency manager versions
- formatters and linters
- pre-commit hooks
Use version files and lockfiles where possible.
Small environment mismatches often create noisy diffs and flaky tests.
Branch Strategy for Multi-Device Work
Avoid coding directly on main across two machines. Use feature branches and keep them focused.
Example naming convention:
When feature work is split into separate concerns, switching devices is safer and pull requests are easier to review.
Conflict Resolution When Both Devices Edit Same Lines
Conflicts happen when both machines modify overlapping lines before sync. Prefer rebase to keep history linear.
If conflicts appear:
- open conflicted files
- keep final intended code
git addresolved files- continue rebase
After rebasing pushed commits, use safe force push:
--force-with-lease is safer than plain --force because it protects against overwriting remote work unexpectedly.
Handling Uncommitted Work Before Switching Computers
If you need to switch quickly, either commit work-in-progress or stash locally.
Later:
Stash is local only. For real cross-device transfer, commit and push to a branch.
Authentication Setup for Two Machines
Use separate SSH keys on each computer and register both public keys in GitHub.
Create key:
Test auth:
Avoid copying one private key file between devices. Separate keys are safer and easier to revoke if one machine is lost.
Helpful Safety Checks Before Push
Run a short checklist before pushing from either machine:
These checks prevent common mistakes such as committing on wrong branch or pushing to wrong remote.
Common Pitfalls
A common pitfall is starting work on machine two without first pulling latest changes. This increases conflict risk immediately.
Another issue is leaving long-lived local commits unpushed on one laptop. If the machine fails, work is lost.
Different formatter settings across devices can also create unnecessary churn in pull requests.
Teams sometimes reuse one branch for unrelated tasks while switching devices. This makes rebases and conflict resolution harder.
Finally, forgetting to align toolchain versions can produce inconsistent test results even with identical code.
Summary
- Clone the same repo on both machines and configure Git identity consistently.
- Follow a strict pull, branch, commit, and push routine when switching devices.
- Keep toolchains aligned to reduce environment-specific breakage.
- Use feature branches and safe rebase workflows for conflict handling.
- Push frequently so GitHub acts as both sync point and backup.

