Git Remote Repositories & GitHub — Complete Collaboration Guide
A remote repository is a hosted copy of your project on GitHub, GitLab, or Bitbucket — it enables team collaboration, offsite backup, and automated deployment pipelines for continuous delivery.
What You’ll Learn
By the end of this tutorial, you’ll add remote repositories, push and pull code, set up SSH key authentication, fork projects, create pull requests, manage multiple remotes, and contribute to open source projects like a professional.
Why Remote Repositories Matter
Without remotes, your code lives only on your machine — one hard drive failure and it’s gone. Remotes provide backup, enable team collaboration, and integrate with CI/CD systems that automatically test and deploy code. DodaTech uses GitHub for all products: Doda Browser releases, DodaZIP builds, and Durga Antivirus Pro signature updates flow through remote repositories with automated pipelines.
Remote Repositories Learning Path
flowchart LR
A[Git Basics] --> B[Branching & Merging]
B --> C[Remote Repositories]
C --> D[Undoing Changes]
D --> E[Advanced Git]
style C fill:#3b82f6,stroke:#fff,color:#fff
git add, git commit, and branching. Review Git if needed.How Remotes Work — The Shared Drive Analogy
Think of a remote repository as a shared office filing cabinet:
- Your local repo is your personal notebook — you write in it privately
- The remote is the shared cabinet — everyone can access it
git push= copying a page from your notebook to the cabinetgit pull= copying the latest pages from the cabinet into your notebookgit fetch= looking at what’s in the cabinet without taking anything
flowchart LR
A[Your Local Repo] -->|git push| B[Remote Repo<br/>GitHub/GitLab]
B -->|git pull| A
C[Teammate's Repo] -->|git push| B
B -->|git pull| C
D[Forked Repo] -->|pull request| B
Adding a Remote
After creating an empty repo on GitHub, connect it to your local project:
git remote add origin https://github.com/user/repo.git
# Verify
git remote -v
# origin https://github.com/user/repo.git (fetch)
# origin https://github.com/user/repo.git (push)Line-by-line explanation:
originis a nickname — the conventional name for the primary remote- The URL tells Git where to send/receive data
-v(verbose) shows all remotes and their URLs
Pushing — Local to Remote
# First push — set upstream tracking
git push -u origin main
# Subsequent pushes (main is now tracked)
git push
# Push a new branch
git push -u origin feature-navbar
# Force push (use with extreme caution)
git push --force origin main
# Safer force push (refuses if remote has new commits)
git push --force-with-lease origin mainLine-by-line:
-usets upstream — it remembers that localmainmaps to remoteorigin/main- After
-u, you can just typegit push— Git knows where to push --forceoverwrites the remote branch — destroys any commits others pushed--force-with-leaseis safer — it checks if you’re aware of remote changes
main or develop without coordinating with your team first. You will delete someone else’s work.Pulling — Remote to Local
# Fetch + merge (most common)
git pull
# Which expands to:
git fetch origin
git merge origin/main
# Pull with rebase instead of merge
git pull --rebaseWhy two commands in one? git pull does two things: downloads new data (fetch) and integrates it (merge or rebase). Most of the time this is what you want — get the latest code and combine it with your work.
Fetch vs Pull — Know the Difference
| Command | What it does | Changes working files? |
|---|---|---|
git fetch | Downloads new data from remote | No |
git pull | Downloads + merges (fetch + merge) | Yes |
git pull --rebase | Downloads + rebase | Yes |
Use git fetch when you want to inspect changes before integrating:
git fetch origin
git log origin/main..main # see what local has that remote doesn't
git diff origin/main # see differences
git merge origin/main # merge when readyAnalogy: git fetch is like looking through the mail without opening any letters. git pull is opening and filing everything immediately.
Cloning — Copying a Remote Repo
# Standard clone
git clone https://github.com/user/repo.git
# Clone into a specific directory name
git clone https://github.com/user/repo.git my-folder
# Clone a specific branch
git clone -b develop https://github.com/user/repo.git
# Shallow clone (only recent history — faster for large repos)
git clone --depth 1 https://github.com/user/repo.gitWhat git clone does automatically:
- Creates a directory named after the repo
- Initializes Git (
git init) - Adds the remote as
origin - Downloads all commits
- Checks out the default branch
SSH Key Authentication
HTTPS requires a personal access token or password every time. SSH is more secure and convenient:
# Generate an Ed25519 key (most secure — 2024+ standard)
ssh-keygen -t ed25519 -C "you@example.com"
# Start ssh-agent and add key
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
# Copy public key
cat ~/.ssh/id_ed25519.pub
# Add this to GitHub → Settings → SSH and GPG keys → New SSH key
# Test connection
ssh -T git@github.com
# Hi username! You've successfully authenticated.Now use the SSH URL format instead of HTTPS:
git clone git@github.com:user/repo.git
git remote set-url origin git@github.com:user/repo.gitWhy SSH? Once set up, you never type a password again. It’s also more secure — your credentials are never transmitted, only your public key.
Forking & Pull Requests
Forking creates a copy of someone else’s repo under your GitHub account:
flowchart LR
A[Original Repo<br/>owner/project] -->|fork| B[Your Fork<br/>you/project]
B -->|clone| C[Local Clone]
C -->|git push| B
B -->|pull request| A
Full Contribution Workflow
# 1. Fork on GitHub (click Fork button)
# 2. Clone your fork locally
git clone https://github.com/YOUR_USERNAME/project.git
cd project
# 3. Add upstream (original repo) as another remote
git remote add upstream https://github.com/owner/project.git
# 4. Create a feature branch
git checkout -b fix-login-bug
# 5. Make changes, commit
git add .
git commit -m "Fix login form validation error"
# 6. Push to your fork
git push -u origin fix-login-bug
# 7. On GitHub, create a Pull Request from your fork/branch
# 8. After PR is merged, sync your fork
git checkout main
git pull upstream main # get latest from original
git push origin main # update your fork on GitHub
# 9. Delete the feature branch
git branch -d fix-login-bug
git push origin --delete fix-login-bugWhy fork instead of branch? You can’t push branches to repos you don’t own. Forking gives you your own copy where you have full write access. The pull request is how you say “please pull my changes into the original.”
Managing Multiple Remotes
git remote -v # list all remotes
git remote add upstream URL # add another remote
git remote remove origin # remove a remote
git remote rename origin upstream # rename a remote
git remote set-url origin NEW_URL # change URL
# Push to a specific remote
git push upstream main
# Fetch from a specific remote
git fetch upstreamCommon setup: origin = your fork, upstream = the original repo you forked from.
Common Mistakes
1. Pushing directly to main in team projects
Direct pushes to main bypass code review and can break the production build. Always use feature branches and pull requests — even for small fixes.
2. Forgetting to pull before pushing
If the remote has new commits you don’t have locally, your push is rejected. Always git pull (or git fetch + git merge) before pushing. Otherwise you get a non-fast-forward error.
3. Mixing HTTPS and SSH remotes
If you cloned via HTTPS but set up SSH keys, git push still asks for a password. Fix with git remote set-url origin git@github.com:user/repo.git.
4. Force-pushing after amending a pushed commit
git commit --amend rewrites the latest commit. If you already pushed it, you’ll need --force-with-lease to push again — which disrupts anyone who pulled the original commit.
5. Not setting upstream for new branches
Running git push on a new branch fails with “fatal: no upstream configured.” Use git push -u origin branch-name for the first push — then plain git push works going forward.
6. Cloning with --depth 1 when you need full history
Shallow clones are fast, but you can’t git log past the shallow boundary, can’t git checkout old commits, and can’t create branches from history. Use git fetch --unshallow to convert later.
Practice Questions
1. What is the difference between git fetch and git pull?
Answer: git fetch downloads new data from the remote without changing your working files. git pull downloads and merges (or rebases) in one step — it changes your working directory.
2. How do you set up SSH authentication for GitHub?
Answer: Generate an Ed25519 key pair with ssh-keygen -t ed25519, add the public key to GitHub Settings, and use SSH URLs (git@github.com:user/repo.git) instead of HTTPS URLs.
3. What is the purpose of a pull request?
Answer: A pull request proposes changes from your branch to another branch. It enables code review, automated testing, and discussion before the changes are merged.
4. How do you sync a forked repository with the original?
Answer: Add the original repo as upstream: git remote add upstream URL. Then git pull upstream main to get changes, and git push origin main to update your fork.
Challenge
Fork any open-source GitHub repo, clone it, add the upstream remote, create a feature branch, make a small improvement (even a README typo fix), push it, and open a pull request. This is the real open-source contribution workflow.
FAQ
Try It Yourself
Practice the full fork → PR workflow:
# 1. Fork any public repo on GitHub (click Fork)
# 2. Clone your fork
git clone https://github.com/YOUR_USERNAME/REPO.git
cd REPO
# 3. Add upstream remote
git remote add upstream https://github.com/ORIGINAL_OWNER/REPO.git
# 4. Create a branch
git checkout -b improve-readme
# 5. Make a small improvement
echo "<!-- This project is awesome -->" >> README.md
git add README.md
git commit -m "Add comment to README for clarity"
# 6. Push to your fork
git push -u origin improve-readme
# 7. Go to GitHub — open a Pull Request from your fork
# 8. After merging, sync your fork
git checkout main
git pull upstream main
git push origin main
git branch -d improve-readmeWhat’s Next
Master Git’s safety net — undoing changes:
| Topic | Description |
|---|---|
| https://tutorials.dodatech.com/devops/git/git-undo/ | Fix mistakes with reset, revert, stash |
| https://tutorials.dodatech.com/devops/git/git-advanced/ | Tags, hooks, submodules, signing |
| https://tutorials.dodatech.com/devops/git/git-reference/ | Quick command cheatsheet |
Related topics to explore:
- Git Overview
- AWS CodeCommit
- CI/CD with Git
- Linux Command Line
What’s Next
Congratulations on completing this Git Remote tutorial! Here’s where to go from here:
- Practice daily — Consistency is more important than long study sessions
- Build a project — Apply what you learned by building something real
- Explore related topics — Check out other tutorials in the same category
- Join the community — Discuss with other learners and share your progress
Remember: every expert was once a beginner. Keep coding!
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro