GitHub
Version Control
Multidevice
Coding Practices
Remote Development

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.

bash
1git clone [email protected]:your-org/your-repo.git
2cd your-repo
3git config user.name "Your Name"
4git config user.email "[email protected]"

If both machines are personal, global config is fine:

bash
git config --global user.name "Your Name"
git config --global user.email "[email protected]"

Also verify remote URLs match your expected protocol, usually SSH.

bash
git remote -v

Daily Cross-Device Workflow

Use this sequence every time you resume work on another machine:

  1. sync main branch
  2. switch to feature branch
  3. pull latest branch updates
  4. make small commits
  5. push frequently

Example:

bash
1git checkout main
2git pull origin main
3git checkout feature/report-export
4git pull --rebase origin feature/report-export

Then code and commit:

bash
git add .
git commit -m "Refine CSV export header mapping"
git push

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.

bash
cat .python-version
cat .nvmrc

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:

text
feature/login-rate-limit
fix/order-timezone-bug
chore/deps-refresh

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.

bash
git fetch origin
git rebase origin/main

If conflicts appear:

  1. open conflicted files
  2. keep final intended code
  3. git add resolved files
  4. continue rebase
bash
git rebase --continue

After rebasing pushed commits, use safe force push:

bash
git push --force-with-lease

--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.

bash
git stash push -m "WIP: retry logic for report job"

Later:

bash
git stash list
git stash pop

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:

bash
ssh-keygen -t ed25519 -C "[email protected]"

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:

bash
1git status
2git branch --show-current
3git log --oneline --decorate -n 5
4git remote -v

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.

Course illustration
Course illustration

All Rights Reserved.