Put your project on GitHub
30 min · Beginner
Need help? Ask a tutor on WhatsApp (opens in a new tab)Showing steps for Windows. They are marked “On Windows” below.
GitHub keeps a copy of your Git repository online. You push your commits there to back them up, to show them to teachers and recruiters, and to share them with teammates.
Git and GitHub
GitHub is a website that stores Git repositories online, so you can back up your code, share it and work on it with other people. It adds team features such as pull requests and issues on top of Git.
Your laptop can break, and a teammate cannot open a folder on it. Git is the program on your laptop that saves commits, even offline. GitHub keeps a second copy of the same repository online.
The two copies stay in step through three commands: git push sends your commits up, git fetch and git pull bring new commits down.
Create an empty repository on GitHub
A remote is a copy of your repository that lives on another computer, usually on a website such as GitHub. Your Git can send commits to it and get commits from it.
Priya's shop-bill folder already has commits, made as in Your first repository and commit (opens in a new tab). She makes an empty repository with the same name on GitHub, so the two can be connected.
- Sign up at github.com with your email; it is free. Pick a username you are happy to show a recruiter, such as
priya-dev. - Click + at the top right, then New repository.
- Type the name
shop-billand a one-line description. - Choose Public (anyone can see it, only you can change it) or Private (only you and the people you invite can see it).
- Leave Add a README, .gitignore and license off: your folder already has its files. Click Create repository.
- GitHub shows a setup page. Copy the HTTPS address:
https://github.com/priya-dev/shop-bill.git.
Connect your folder: origin
origin is the short name Git uses for the main remote of a repository. You type origin instead of the long GitHub address. git clone sets it up for you; git remote add creates it by hand.
Typing the full address in every command is slow and easy to get wrong. git remote add saves it once under a short name, and git remote -v lists what is saved. Run both inside the project folder, the one that holds .git.
On Windows
On Windows these lessons use PowerShell (Start menu → PowerShell, or the terminal inside VS Code). Git Bash prints the same Git output.
PS C:\Users\Priya\shop-bill> git remote add origin https://github.com/priya-dev/shop-bill.gitPS C:\Users\Priya\shop-bill> git remote -vOutputorigin https://github.com/priya-dev/shop-bill.git (fetch) origin https://github.com/priya-dev/shop-bill.git (push)
git remote addprints nothing when it works: it saved the address under the nameorigin.git remote -vshows the address twice: one is used to fetch (download), the other to push (upload).
Made a typo in the address? git remote set-url origin <correct-address> replaces it. Running git remote add origin a second time only prints error: remote origin already exists.
Push your commits: git push -u
Push means sending the commits on your laptop to a remote such as GitHub. git push uploads only the commits the remote does not have yet; changes you have not committed are not sent.
The first push of a branch names where to send (origin) and which branch (main). The -u part links your main to GitHub's, so after this a plain git push is enough.
On Windows
On the first push, Git Credential Manager (it comes with Git for Windows) opens a GitHub sign-in window. Choose Sign in with your browser and approve it once. Windows remembers you, so you never type a GitHub password in PowerShell.
Example · The first push
Runs in: Your terminal
PS C:\Users\Priya\shop-bill> git push -u origin mainPS C:\Users\Priya\shop-bill> git statusOutputEnumerating objects: 6, done. Counting objects: 100% (6/6), done. Delta compression using up to 12 threads Compressing objects: 100% (4/4), done. Writing objects: 100% (6/6), 661 bytes | 66.00 KiB/s, done. Total 6 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0) To https://github.com/priya-dev/shop-bill.git * [new branch] main -> main branch 'main' set up to track 'origin/main'. On branch main Your branch is up to date with 'origin/main'. nothing to commit, working tree clean
What this code does
- Before these lines, a browser window asked Priya to sign in to GitHub. That happens only once.
* [new branch] main -> mainmeans GitHub now has hermainbranch with both commits.set up to track 'origin/main'is what-udid, andgit statusnow comparesmainwith GitHub's copy: up to date.
From now on the daily habit is short: commit, then git push. Refresh the repository page on GitHub to see your files and the number of commits.
Signing in: a token or an SSH key
A personal access token is a long secret code that GitHub makes for you to use instead of your password when Git signs in over HTTPS. You choose what it may do and when it expires, and you can delete it at any time.
GitHub stopped accepting account passwords for Git in 2021. Over an https:// address you sign in through the browser or with a token. To make a token:
- On GitHub: your profile picture → Settings → Developer settings → Personal access tokens → Fine-grained tokens → Generate new token.
- Give it a name such as
laptop, an expiry date and access to your repositories. - Under Repository permissions, set Contents to Read and write, then click Generate token.
- Copy it now: GitHub shows it only once. Treat it like a password: never put it in a file, a commit or a chat.
On Windows
On Windows you rarely need the token: Credential Manager signs in through the browser. The other way is an SSH key, a pair of files that proves who you are with no password at all. Make one in PowerShell, press Enter at each question, then copy the public key:
PS C:\Users\Priya> ssh-keygen -t ed25519 -C "priya@example.com"PS C:\Users\Priya> Get-Content C:\Users\Priya\.ssh\id_ed25519.pub | Set-ClipboardOutputGenerating public/private ed25519 key pair. Enter file in which to save the key (C:\Users\Priya/.ssh/id_ed25519): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in C:\Users\Priya/.ssh/id_ed25519 Your public key has been saved in C:\Users\Priya/.ssh/id_ed25519.pub The key fingerprint is: SHA256:uA93SnVTM+aA4josWjBnTEw4YHVh/ZwncBRrqL56vdk priya@example.com
- The keys live in
C:\Users\Priya\.ssh:id_ed25519is the private key (never share it) andid_ed25519.pubis the public key. Get-Content ... | Set-Clipboardcopies the public key, ready to paste on GitHub.
git:https://github.com and push again.Then on GitHub: Settings → SSH and GPG keys → New SSH key, paste and save. Switch the repository to the SSH address with git remote set-url origin git@github.com:priya-dev/shop-bill.git.
Next step
Check your understanding
10 quick questions