Clone, push and pull are how you share work through GitHub. In this lesson you will clone repositories, push your commits with upstream tracking, pull your team’s changes, handle rejected pushes and use force-push safely.
📖 What You’ll Learn: git clone and its options, the first push with -u, plain git push, rejected pushes, –force vs –force-with-lease, git pull and pull –rebase, a daily team routine, and common clone, push and pull errors.
🔁 The Three Commands That Connect You to GitHub
| Command | Direction | What it does |
|---|---|---|
git clone | GitHub → your computer (once) | Downloads a full copy of a repository, with its history |
git push | Your computer → GitHub | Uploads your new commits |
git pull | GitHub → your computer | Downloads new commits and merges them into your branch |
📥 git clone: Get a Copy of a Repository
On any GitHub repository page, click the green Code button and copy the HTTPS or SSH URL:
git clone git@github.com:microsoft/playwright.git
git clone https://github.com/asha-verma-qa/git-practice.git my-practice # into a custom folder name
Cloning into 'git-practice'...
remote: Enumerating objects: 15, done.
Receiving objects: 100% (15/15), done.
What you get:
- A new folder with all files of the default branch.
- The complete history (
git logworks offline). - A remote called
originpointing to the URL (remotes). - A local
mainbranch that tracksorigin/main.
Useful clone options
| Command | Use |
|---|---|
git clone --branch develop <url> | Check out a specific branch after cloning |
git clone --depth 1 <url> | Shallow clone: only the latest snapshot (fast for CI and huge repos) |
git clone --recurse-submodules <url> | Also clone submodules |
📤 git push: Send Your Commits to GitHub
First push of a branch
git push -u origin main
Enumerating objects: 6, done.
Writing objects: 100% (6/6), 512 bytes | 512.00 KiB/s, done.
To github.com:asha-verma-qa/git-practice.git
* [new branch] main -> main
branch 'main' set up to track 'origin/main'.
-u (--set-upstream) links your local main to origin/main. After that, a plain command is enough:
git push
💡 Tip: With git config --global push.autoSetupRemote true (from Configure Git), the first git push of any new branch sets the upstream automatically.
When push is rejected
! [rejected] main -> main (fetch first)
error: failed to push some refs to 'github.com:asha-verma-qa/git-practice.git'
hint: Updates were rejected because the remote contains work that you do not have locally.
Someone else pushed first. Get their commits, then push again:
git pull
git push
Force push (use with care)
After rewriting history (for example a rebase), a normal push is rejected. Prefer the safer form:
git push --force-with-lease
--force-with-lease refuses to overwrite the remote if someone else pushed commits you have not seen. Plain --force overwrites blindly.
⚠️ Common mistake: Never force-push to shared branches such as main or develop. It can delete teammates’ work. Many teams block it with branch protection.
📥 git pull: Get Your Team’s Changes
git pull
Updating 8b1d4e2..c4d5e6f
Fast-forward
tests/login.spec.ts | 12 ++++++++++++
1 file changed, 12 insertions(+)
git pull is two commands in one: git fetch (download) and git merge (integrate). If you and a teammate changed the same lines, you get a merge conflict. The difference between fetch and pull has its own lesson.
git pull origin main # pull a specific branch from a specific remote
git pull --rebase # replay your local commits on top instead of merging
🔄 A Daily Team Routine
git pull # 1. start the day up to date
# ... edit files ...
git add .
git commit -m "Add API tests for orders endpoint" # 2. commit small changes often
git pull # 3. integrate teammates' work before pushing
git push # 4. share your work
In real teams you push to a feature branch and open a pull request instead of pushing to main directly. Branches are next in Module 4.
🐞 Common Errors
| Error | Fix |
|---|---|
fatal: repository not found | Wrong URL or no access; check git remote -v and your GitHub permissions |
Permission denied (publickey) | SSH key not set up; see SSH keys or use HTTPS |
Authentication failed (HTTPS) | Passwords are not accepted; use Git Credential Manager or a personal access token |
rejected (fetch first) | Run git pull, resolve any conflicts, then push |
There is no tracking information for the current branch | Push once with git push -u origin <branch> |
📝 Assignment
- Push your local
git-practicerepository to GitHub withgit push -u origin mainand refresh the GitHub page. - Clone the same repository into another folder (
git clone <url> practice-copy). - In the copy, make a commit and push it. In the original folder, run
git pulland checkgit log --oneline. - Make commits in both folders, push from one, and push from the other to see the “rejected” message. Fix it with
git pulland push again. - Clone a popular open-source repository with
--depth 1and compare its size with a full clone.
❓ FAQ
🤔 How do I push code to GitHub?
Commit your changes, then run git push. For the first push of a branch use git push -u origin <branch> to set the upstream.
🤔 What does git push -u origin main mean?
Push the local main branch to the remote origin and remember origin/main as its upstream, so later you can just run git push and git pull.
🤔 What is the difference between git clone and git pull?
git clone creates a new local copy of a repository once. git pull updates an existing local copy with new commits from the remote.
🤔 Why is my git push rejected?
The remote has commits you do not have. Run git pull, resolve conflicts if any, then push again.
🤔 What is the difference between –force and –force-with-lease?
--force overwrites the remote branch unconditionally. --force-with-lease only overwrites it if nobody else has pushed in the meantime, which is much safer.
🎯 Next Steps
- ⚖️ git fetch vs git pull
- 🚀 Push an Existing Project to GitHub
- 📘 Git and GitHub Tutorial: full course
🎬 Learn Git and GitHub step by step: watch the series on YouTube!
Subscribe to SqaToolsByDY • Practice on sqatools.in
3 thoughts on “git clone, git push and git pull Explained Step by Step”