GitHub Repositories
6 learning objectives · 9 key terms · 8 commands · 3 diagrams · 5 quiz questions
GitHub Repositories
FoundationsWhat you'll be able to do
- Create a GitHub repository with a sensible name, description and visibility
- Choose between public and private repositories, and know when to change your mind
- Use README, license and .gitignore from the start so the project explains itself
- Clone a remote repository and connect an existing local one
- Push local commits up and pull teammates’ commits down safely
- Distinguish git fetch, git pull and git push precisely
The idea, in plain language
A GitHub repository is a Git repository plus the context a stranger needs: a name, a one-line description, a README that renders on the front page, a topic list, and permission settings that decide who can read or write. When you create one in the browser, GitHub can supply the three files a healthy project starts with — a README, a .gitignore matching your language, and a license — and it makes an initial commit on your behalf. Because that first commit exists on GitHub and not on your laptop, the local project you already have and the remote you just created need to be connected deliberately.
Connecting them is a two-line job: register the remote with a name (by strong convention, origin) and a URL, then push your branch and set its upstream so later pushes and pulls know where to go. From then on the remote is just another copy of the same repository that happens to live on a server. Your local branch and its remote-tracking counterpart move independently — you can accumulate five local commits while GitHub still shows the old state, and nothing is inconsistent about that; git status simply reports you are ahead.
That independence is the key to the three sync commands. git fetch downloads new objects and updates your remote-tracking branches but never edits your files, so it is always safe. git pull is git fetch followed by an integration step (merge by default, rebase if you configure it), so it does change your working directory and can produce conflicts. git push uploads your local commits and is the only one of the three that changes what other people can see.
Key terms
- origin
- The conventional name for the remote you cloned from or push your work to.
- upstream branch
- The remote branch a local branch tracks, so plain git push and git pull know where to go.
- Remote-tracking branch
- Your local record of where a remote branch stood the last time you fetched, such as origin/main.
- Clone
- A full copy of a remote repository, including history, plus the origin remote configured for you.
- README.md
- The Markdown file GitHub renders on the repository home page — the project’s front door.
- License
- The file that states what others are legally allowed to do with your code.
- Visibility
- Public (anyone can read) or private (only invited collaborators can).
- Ahead / behind
- How many commits your local branch has that the remote does not, and vice versa.
- Personal access token
- A scoped password replacement used for HTTPS authentication.
How it works, step by step
- 1Create the repository on GitHub
Name it in lowercase with hyphens, write a one-line description (it appears in search and on your profile), and pick visibility. Tick "Add a README file", "Add .gitignore" and "Choose a license" — these three files on day one save hours later.
or the browser, or the CLIbashgh repo create recipe-book --public --description "A tiny recipe manager" --clone
- 2Clone it (new project) or connect it (existing project)
Cloning gives you the repository plus the origin remote already wired up. If you already have local commits, add the remote instead and push.
new projectbashgit clone git@github.com:ada/recipe-book.git cd recipe-book
- 3Point an existing repository at GitHub
Register the remote, make sure your branch is called main, then push and set the upstream so future pushes need no arguments.
existing projectbashgit remote add origin git@github.com:ada/recipe-book.git git branch -M main git push -u origin main
- 4Confirm the wiring
git remote -v prints each remote with its fetch and push URLs. If the URL is wrong, nothing else will work — fix it with git remote set-url.
verifybashgit remote -v - 5Fetch to look, pull to integrate
Run git fetch to see what changed on the remote without touching your files, then git pull when you are ready to actually bring those commits into your branch.
keep up to datebashgit fetch origin git status git pull origin main
- 6Push your work
After the first push with -u, plain git push sends the current branch to its upstream. Pushing is publishing: everything you push is visible to whoever can read the repository.
publishbashgit push
Commands worth memorising
Every block below is copy-ready — use the Copy button, then paste it into your terminal. Expected output is shown underneath so you know what “working” looks like.
git clone git@github.com:ada/recipe-book.git
Cloning into 'recipe-book'... remote: Enumerating objects: 12, done. Receiving objects: 100% (12/12), done.
Downloads the full repository and configures origin for you.
git remote -vorigin git@github.com:ada/recipe-book.git (fetch) origin git@github.com:ada/recipe-book.git (push)
Run this whenever a push goes somewhere unexpected.
git remote add origin <repository-url>
Connects a repository you created locally to one you created on GitHub.
git remote set-url origin <new-repository-url>
Renamed the repository on GitHub? Update the URL rather than removing and re-adding the remote.
git push -u origin mainbranch 'main' set up to track 'origin/main'. To github.com:ada/recipe-book.git * [new branch] main -> main
The -u is needed once per branch; afterwards plain git push and git pull work.
git fetch origin --pruneDownloads new commits and drops remote-tracking branches that no longer exist. Never modifies your working files.
git pull --rebase origin mainFetch, then replay your local commits on top of the remote ones — keeps history linear.
git status -sb## main...origin/main [ahead 2]
Ahead 2 means two local commits are waiting to be pushed; behind means you should pull.
Workflow diagrams
The two copies move independently. Only push, fetch and pull cross the boundary.
- git push sends local commits to GitHub and is the only command that changes what others see.
- git fetch downloads new remote commits into your remote-tracking branches without touching your files.
- git pull is fetch plus merge or rebase, so it does change your working directory and can conflict.
- Committing locally while the remote is behind is normal — git status shows you are ahead, not broken.
| Command | Direction | Touches your files? | When to use |
|---|---|---|---|
| git fetch | GitHub → your machine | No | To see what changed before deciding whether to integrate |
| git pull | GitHub → your machine, then integrate | Yes | To bring teammates’ commits into your current branch |
| git push | Your machine → GitHub | No (uploads commits) | To publish commits so others can see them |
| git clone | GitHub → new folder | Creates files | Once, to start working on an existing repository |
The direction is what matters: these three commands are the entire network surface of daily Git work.
- fetch is the safe read-only glance at the remote.
- pull is fetch plus integration, which is why it can raise merge conflicts.
- push publishes; it fails if the remote has commits you have not integrated yet.
The order matters. Pushing into a remote that has its own commits is rejected, and that rejection is Git protecting your history.
- If you ticked "Add a README" when creating the repository, GitHub already has a commit your clone does not know about.
- Pull with rebase first so your local commits are replayed on top of it, then push.
- If the repository is completely empty, push straight away with git push -u origin main.
Worked example
The full path from an empty GitHub repository to a synced pair, using the terminal the whole way.
cd recipe-book git remote add origin git@github.com:ada/recipe-book.git git branch -M main git push -u origin main # To github.com:ada/recipe-book.git # * [new branch] main -> main # branch 'main' set up to track 'origin/main'. git remote -v # origin git@github.com:ada/recipe-book.git (fetch) # origin git@github.com:ada/recipe-book.git (push) git status -sb # ## main...origin/main # a teammate pushes a commit; check before integrating git fetch origin # remote: Enumerating objects: 5, done. git status -sb # ## main...origin/main [behind 1] git pull --rebase # Successfully rebased and updated refs/heads/main.
Your local branch now tracks origin/main, and the repository is visible on GitHub with the full history.
Where you'll use it
Common mistakes
- Creating the GitHub repository with a README and then trying to push a local history that has no common ancestor — the push is rejected and looks broken.
- Working for days without pushing, then discovering a teammate built a completely different solution.
- Committing a client’s secrets into a public repository — visibility is public forever, even after deletion.
- Using git pull blindly on a branch with local uncommitted changes and ending up mid-merge with no idea how to finish.
- Pulling instead of fetching when you only wanted to look, then having to unwind an unwanted merge.
- Forgetting the -u on the first push and then wondering why plain git push complains about no upstream.
Best practices
- Give every repository a one-line description and a README that says what it is, why it exists and how to run it.
- Add a license deliberately — its absence means "all rights reserved" whether you intended that or not.
- Fetch before you pull when you are unsure; the worst case of fetching is nothing at all.
- Push at least at the end of every working session so the remote is never far behind reality.
- Use SSH keys or a personal access token instead of typing a password, and keep those credentials out of the repository.
- Name repositories in lowercase-with-hyphens so URLs, clones and imports stay predictable.
Hands-on exercise
Publish a local repository and practise the three sync commands
Connect a repository you already have to GitHub and move commits in both directions.
- On GitHub, create a repository named git-practice with a description and a README, and set it to public.
- Clone it, then add a file and commit it locally. Push and confirm the file appears on GitHub.
- Without pushing, make two more local commits, then run git status -sb and read the ahead count.
- On GitHub, edit the README in the browser and commit the change there — this simulates a teammate.
- Back in the terminal run git fetch, then git status -sb, and note that your files have not changed even though Git now knows about the new remote commit.
- Run git pull --rebase, then git log --oneline --graph, and push, so both copies match again.
💡 Hint: If the push after step 2 is rejected with "updates were rejected because the remote contains work that you do not have locally", fetch and rebase before pushing.
Done when: git status -sb prints ## main...origin/main with no ahead or behind count, and GitHub shows every commit you made locally.
Checkpoint quiz
0 of 5 answered · 0 correct
- Multiple choiceQ1
Which command downloads new commits from GitHub without changing your working files?
- Command outputQ2
What does this status line mean?
## main...origin/main [ahead 3]
- TroubleshootingQ3
Your first push to a brand-new GitHub repository is rejected, saying the remote contains work you do not have locally. The repository was created with a README. What is the cleanest fix?
- True or falseQ4
True or false: a repository can be public on GitHub with no license, which means others may reuse the code freely.
- Multiple choiceQ5
What does the -u flag on git push -u origin main do?
Module summary
- A GitHub repository = a Git repository plus README, description, license, visibility and permissions.
- Cloning sets up origin for you; connecting an existing project needs git remote add plus a first push with -u.
- git remote -v is the first thing to check when pushes go somewhere unexpected.
- fetch looks, pull integrates, push publishes — only push changes what other people see.
- Local and remote histories can legitimately differ; git status -sb tells you which way to reconcile.
- Visibility is a security decision, and a license is a legal one — both belong on day one.
Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Put the GitHub course to work: open one of the company-wise repositories and follow the workflow you just learned, branch to release.