One Shared Folder, Not Fifty Forwarded Copies
Think about how a class shares notes. In a WhatsApp group, everyone forwards their own copy: “notes_final.pdf”, “notes_final_new.pdf”, “notes_final_REAL.pdf”. Soon nobody knows which one is latest. In a shared online folder, like a Google Drive folder, there is one place. Everyone adds to it and everyone sees the latest version.
GitHub gives your Git project that shared place. In the last lesson, Asha created an empty repository called college-fest-site on GitHub. Now she will push her code there. Ravi will clone it to his laptop, and when Imran adds a page, Asha will pull it down. These three words are the heart of working with GitHub.
GitHub: asha-utsav-demo/college-fest-site
(the shared copy, "origin")
^ | | ^
push | | pull clone | | push
| v v |
Asha's laptop Ravi's laptop
| Command | Direction | In simple words |
|---|---|---|
git push | Your computer to GitHub | Upload my new commits |
git pull | GitHub to your computer | Download new commits from others and add them to my copy |
git clone | GitHub to your computer, once | Download the whole project for the first time |
Step 1: Connect Your Project to GitHub with git remote
A remote is a saved address of another copy of your repository, usually on GitHub. By custom, the main remote is called origin. Copy the HTTPS address from your GitHub repository page and run:
# Go into the project folder
cd college-fest-site
# Connect it to GitHub and call that connection "origin"
git remote add origin https://github.com/asha-utsav-demo/college-fest-site.git
# List the remotes to check the address
git remote -v
git remote -v (v for “verbose”) lists every remote. You will see something like:
origin https://github.com/asha-utsav-demo/college-fest-site.git (fetch)
origin https://github.com/asha-utsav-demo/college-fest-site.git (push)
Two lines with the same address is normal: one for downloading (fetch) and one for uploading (push). This step is done once per project.
Step 2: Your First Push with git push -u origin main
Now Asha uploads her commits:
# Upload the main branch to origin, and remember this pairing (-u)
git push -u origin main
Read it as: “push to origin the branch called main”. The -u option (short for --set-upstream) makes Git remember that your local main belongs with main on origin. After this, a plain git push or git pull knows where to go.
On the very first push, Git must sign in to GitHub. On Windows, Git Credential Manager opens a browser window: sign in and authorize, and you will not be asked again. If you set up a personal access token or SSH key in the last lesson, that is used instead. You will see something like this (numbers will differ):
Enumerating objects: 15, done.
Counting objects: 100% (15/15), done.
Writing objects: 100% (15/15), 2.10 KiB | 2.10 MiB/s, done.
Total 15 (delta 3), reused 0 (delta 0), pack-reused 0
To https://github.com/asha-utsav-demo/college-fest-site.git
* [new branch] main -> main
branch 'main' set up to track 'origin/main'.
Now refresh the repository page on GitHub. Asha’s files are there, with her commit messages next to them. Click the commits count to see the same history that git log shows on her laptop.
Step 3: Later Pushes Are Just git push
From now on, the routine is short. Commit locally, then push:
# Asha edits events.html, then saves a commit as usual
git add events.html
git commit -m "Add dance competition timings"
# Thanks to -u, a plain push is enough now
git push
You will see something like:
To https://github.com/asha-utsav-demo/college-fest-site.git
a1b2c3d..e4f5a6b main -> main
a1b2c3d..e4f5a6b means GitHub’s main moved from the old commit to the new one. Your IDs will differ.
Push only sends commits. Files you changed but did not commit stay on your laptop. If GitHub does not show your change, run git status: you probably forgot to commit.
Step 4: Ravi Joins with git clone
Before Ravi can push, Asha invites him: on GitHub she opens the repository’s Settings, then Collaborators, and adds ravi-utsav-demo. Ravi accepts the invitation from his email. Then, on his own laptop, he copies the address from the green Code button and runs:
# On Ravi's laptop: go to the folder where he keeps projects
cd Desktop
# Download the whole repository, with all its history
git clone https://github.com/asha-utsav-demo/college-fest-site.git
# Move into the new folder and look at the history
cd college-fest-site
git log --oneline
You will see something like:
Cloning into 'college-fest-site'...
remote: Enumerating objects: 18, done.
remote: Total 18 (delta 4), reused 18 (delta 4), pack-reused 0
Receiving objects: 100% (18/18), done.
Resolving deltas: 100% (4/4), done.
git clone creates a new folder, downloads every file and the full history, and sets up origin for you. Ravi does not need git init or git remote add. He does need his own name and email in git config, as in the setup lesson. Clone happens once per computer; after that, he uses pull and push.
Step 5: Getting Your Friends’ Work with git pull
Imran has cloned the project too, and pushed a new sponsors.html page. Asha does not have it yet. She runs:
# Asha downloads Imran's new commits and adds them to her copy
git pull
You will see something like:
remote: Enumerating objects: 5, done.
Unpacking objects: 100% (3/3), done.
From https://github.com/asha-utsav-demo/college-fest-site
e4f5a6b..c7d8e9f main -> origin/main
Updating e4f5a6b..c7d8e9f
Fast-forward
sponsors.html | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
create mode 100644 sponsors.html
git pull does two jobs: it fetches new commits from GitHub, then merges them into your branch. “Fast-forward” means Asha had no new commits of her own, so Git simply moved her main ahead. You will learn about fetch and merge in detail in the coming lessons on branches, merging and remotes.
Real-Life Example: The Team’s Daily Routine
With three people working on one website, the team agrees on one habit: pull first, push last. Every evening each of them follows the same four steps:
# 1. Start of the day: get your friends' work
git pull
# 2. Work: edit files in VS Code, save, test in the browser
# 3. Save your work in Git
git status
git add .
git commit -m "Describe what you changed"
# 4. Share it
git push
Pulling first means you start from the newest version, so there is less chance of two people changing the same lines. Pushing at the end means your friends get your work the next time they pull. This is the shared folder from the opening, working properly.
Try these changes:
- Edit a file directly on GitHub (pencil icon) and commit it there. Then run
git pullon your computer and see the change arrive. - Run
git statusright after a push. It should say your branch is up to date withorigin/main.
Common Mistakes
1. “Rejected, fetch first”: someone pushed before you
Ravi pushed, and then Asha tries to push her own commit. GitHub has work she does not have, so it refuses:
! [rejected] main -> main (fetch first)
error: failed to push some refs to 'https://github.com/asha-utsav-demo/college-fest-site.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. ...
The fix is to pull first, then push:
# Tell Git to combine histories with a merge when you pull (do this once)
git config --global pull.rebase false
# Get the new work from GitHub, then push again
git pull
git push
If you both made commits, Git combines them with a merge commit and may open your editor (VS Code, if you set it up in the setup lesson) with the message "Merge branch 'main' of ...". Close that tab to accept the message. (If Vim opens instead, type :wq and press Enter.) Without the pull.rebase setting, newer Git versions stop with “You have divergent branches” and ask you to choose. If you both edited the same lines, Git reports a conflict, which you will learn to fix in the merge lesson.
2. Authentication failed
remote: Support for password authentication was removed ...
fatal: Authentication failed for 'https://github.com/asha-utsav-demo/college-fest-site.git/'
You typed your GitHub password, which Git no longer accepts. Fix: use the browser sign-in of Git Credential Manager, or paste a personal access token when asked for a password. If a saved token has expired, remove the old GitHub entry from Windows Credential Manager or the Mac Keychain and push again.
3. Pushing to the wrong remote
A typo in the address gives “Repository not found”, and running git remote add origin twice gives “remote origin already exists”. Always check, then fix the address:
# See where origin points
git remote -v
# Point origin at the correct address
git remote set-url origin https://github.com/asha-utsav-demo/college-fest-site.git
4. Cloning inside another repository
Running git clone while you are inside another project folder puts one repository inside another. Fix: cd to a normal folder such as Desktop or Documents first.
Practice Task: Sync Between Two Folders
You can practise teamwork alone by using two folders as two “computers”. Do this in your own terminal:
- On GitHub, create an empty public repository called
sync-practice. - On your computer, create a
sync-practicefolder with oneindex.html, rungit init -b mainand commit. - Add the remote, check it with
git remote -v, and push with-u. - Go up one folder and clone the repository into a second folder called
sync-copy. - In
sync-copy, changeindex.html, commit and push. - Go back to
sync-practice, rungit pull, and check that the change arrived.
Show one possible answer (try it yourself first!)
# On GitHub: create an EMPTY public repository named sync-practice
# 1. Create the local project
mkdir sync-practice
cd sync-practice
git init -b main
echo "<h1>Sync practice</h1>" > index.html
git add index.html
git commit -m "Add home page"
# 2. Connect and push (use your own username)
git remote add origin https://github.com/your-username/sync-practice.git
git remote -v
git push -u origin main
# 3. Pretend to be a second computer: clone into another folder
cd ..
git clone https://github.com/your-username/sync-practice.git sync-copy
cd sync-copy
echo "<p>Added from the second copy</p>" >> index.html
git add index.html
git commit -m "Add a paragraph from the second copy"
git push
# 4. Back in the first folder, get that change
cd ../sync-practice
git pull
git log --oneline
Key Takeaways
- A remote is a saved address of another copy of your repository.
originis the usual name. Check it withgit remote -v. git push -u origin mainuploads your commits the first time and remembers the pairing. After that, usegit push.git clone <url>downloads a whole project with its history, once per computer.git pulldownloads and merges your teammates’ new commits.- Daily routine: pull, work, add, commit, push. If a push is rejected, pull first.