Remote Repositories and Github
You synchronize your local repo with a remote repo.
You do your day-to-day work in a local repository.
You upload your local changes to the remote repo.
Repeat steps 2-3
A remote repository is a copy of your Git project hosted on a server that is accessible over the internet or a network.
Your local repo sits on your computer
The remote repo lives on a centralized infrastructure
Two primary purposes:
Remote repositories are good for collaboration1
They are also good as a backup (or “solitary reproducibility”)
Offsite Backup & Disaster recovery: Protects research from local hardware failures.
Hardware Mobility: Seamlessly move code between a laptop and a lab’s computing cluster.
Public Provenance: Serves as a timestamped, immutable record of scientific development.
Public Inspection: True reproducibility requires third-party verification. Remote repos allow peer-reviewers and the public to audit your work.
GitHub: The industry standard and largest host in the world. It is the default platform for open-source software, academic packages, and community-driven reproducible research.
GitLab: A powerful alternative heavily favored by enterprises and institutional research centers. Many universities host their own self-managed GitLab instances on internal servers to comply with strict data privacy laws.
Bitbucket: Owned by Atlassian, this platform is frequently used in corporate environments that rely heavily on Jira for project management.
BTW: We’re going to focus on GitHub. You’ll get formally introduced to GitHub in lab.
Web-based platform that hosts Git repositories in the cloud.
Used by developers store, share, and collaborate on software code.
Created in 2008; Acquired by Microsoft in 2018.
Provides:
GitHub \(\neq\) Git
Working with remote repositories requires internet connectivity.
Remote repositories introduce an extra step in your workflow. After making local commits, you need to explicitly upload them to the remote repo.
Hosting service issues:
git push?When you run git push origin main
Git checks which commits exist locally but not on the remote.
Git compresses these commits and sends them to GitHub.
GitHub receives the commits and updates the remote branch.
GitHub sends a confirmation message back to your local Git.
The moment the local Git engine receives that success confirmation from GitHub, it instantly updates the local origin/main pointer forward to the last commit.
Local main and local origin/main are perfectly aligned, pointing to the last commit.
originAnalogy:
origingit@github.com:yourusername/your-repo.gitorigin is just a shortcut nickname.
It is NOT the name of a branch
Why use it? Typing long cryptographic SSH URLs every time you save your work is annoying.
The Mapping: Git maps the short nickname origin to your specific, secure URL on GitHub.
Flexibility: You could technically rename origin to github, backup, or cloud (Git doesn’t care!)
origin/mainserver/branchmain branch that lives on the origin serverpush, fetch, pull)origin/main is like a contact’s “Last Seen” timestamp. It doesn’t track what GitHub is doing in real-time;Local Repo
Remote Repo
git push Syntaxgit push syntaxThe simplest form of git push looks like this:
<remote> is the name of your remote repository (usually origin)
<branch> is the branch you want to push
Assume that the URL of the remote repository is: git@github.com:yourusername/your-repo.git
Step 2) Once a remote repo has been added, check your remote connection
Step 3) Make sure you have commits
If you see commits listed, you’re ready to push. If not, make some changes and commit them first.
Step 4) Now push your commits to GitHub:
Every time you push, you might get tired of typing git push origin main.
Git offers a shortcut using upstream tracking.
When you set an upstream branch, Git remembers which remote branch corresponds to your local branch.
Then you can just type git push without specifying the remote and branch.
Now you can simply use:
Example:
You can push any local branch to GitHub, not just main.
This is useful when working on features or bug fixes.
Example: Say you created a feature branch called add-login (and made some commits):
There’s no strict rule, but here are some good practices:
After completing a logical unit of work: When you finish a feature, fix a bug, or reach a stable state.
Before ending your work session: Push at the end of the day so your work is backed up.
Before switching computers: Push from one machine so you can pull on another.
When collaborating: Push regularly so teammates can see your progress.
Avoid pushing broken code or work-in-progress changes to the main branch. Use feature branches for incomplete work.
This error happens when the remote branch has commits that you don’t have locally:
If you try to use git push without setting upstream tracking first, you’ll see:
If your credentials are incorrect or expired, you’ll see:
Solution: Check GitHub’s authentication settings.
Follow these guidelines to avoid common problems:
Always commit before pushing: You can’t push uncommitted changes.
Use meaningful commit messages: Others will see your commits on GitHub.
Pull before pushing: Especially in team projects, check for remote changes first.
Push feature branches separately: Keep experimental work isolated from main.
Don’t force push: Avoid git push --force unless you understand the consequences.
