New to Rust? Grab our free Rust for Beginners eBook Get it free →
GitHub Tutorial for Beginners: First Repository

Starting a first repository means recording a project snapshot on your computer and sending it to GitHub. Git tracks project history, and GitHub hosts a remote copy for sharing and review.
You’ll learn how Git and GitHub differ, then follow the steps to create and push your first repository.
TL;DR
Git records project history on your computer, while GitHub hosts a remote copy and adds tools for sharing and review. To publish a first project, initialize Git, stage and commit a file, create an empty GitHub repository, connect it as origin, then push your branch.
- Install Git and set a commit name and email.
- Use git status to see what will be staged before committing.
- Use a personal access token or an SSH key for command-line authentication, not your account password.
What Are Git and GitHub?
Git is distributed version control software. GitHub hosts repositories for sharing and review.
| Term | What it means | Where it lives |
|---|---|---|
| Working tree | Files you edit | Your project folder |
| Staging area | Selected changes queued for the next commit | Your local repository |
| Commit | A recorded snapshot with a message | Your local history |
| Remote | A named connection to another repository | For example, GitHub |
How to Create and Push a GitHub Repository Step by Step
Start with a local project and an empty remote repository so the first push has one clear source of history. The commands below use a folder named hello-github and a branch named main.
Step 1: Install Git and set your commit identity
Install Git from the official download page for your operating system and verify that the command runs. This check returned git version 2.43.0 and showed the local branch as main.
./setup_check.sh
pankaj@codeforgeek:~$ ./setup_check.sh
git version 2.43.0
main

Set the commit name and email for this repository from its folder. These local settings identify new commits without changing settings for other projects. They are commit metadata, not a sign-in credential.
git config user.name "Your Name"
git config user.email "[email protected]"
GitHub offers private or no-reply addresses for commit metadata. Check its email privacy settings if you do not want a personal address shown publicly.
Step 2: Initialize a local repository
Create a project folder, move into it, and start Git with main as the initial branch.
State what the project does and include the commands needed to install or run it. Update those instructions when setup changes, so the repository page remains useful.
mkdir hello-github
cd hello-github
git init -b main
printf "# Hello GitHub\n" > README.md
The branch option names the initial branch. If your installed Git does not support it, initialize without that option and rename the branch with the branch rename command. Check the branch shown by git status.
Step 3: Stage a file and create the first commit
Staging selects which current file changes belong in a commit. Check the working tree, stage the README, check again, and then record the snapshot with a message that describes the change.
git status --short
git add README.md
git status --short
git commit -m "Add project README"
Git reports an untracked README before staging, then records the commit after staging. For this workflow I used a named shell script that initialized a repository, staged README.md and committed it. The captured output was:
pankaj@codeforgeek:~$ ./git_github_demo.sh
?? README.md
[main (root-commit) b7766fc] Add README
1 file changed, 1 insertion(+)
create mode 100644 README.md
b7766fc Add README

The commit hash identifies this snapshot in the local history. Your hash will differ because each commit has its own content and metadata.
Step 4: Create an empty repository on GitHub
Sign in to GitHub and create a repository with a short project name. For this route, leave the options to add a README, license or Git ignore file unchecked because those files already belong in the local project or can be added later.
Choose public or private visibility based on who should be able to view the project. Public repositories can be browsed by anyone, while private repositories limit access to people you authorize. Private visibility does not replace credential hygiene, so keep secrets out of either kind.
Copy either the HTTPS or SSH URL from the GitHub repository page and keep it ready for the next command.
Step 5: Connect the remote and push your branch
A remote gives your local repository a name for the hosted copy. Git conventionally calls the primary remote origin. Replace the example URL with the one shown on your repository page.
git remote add origin https://github.com/USERNAME/hello-github.git
git remote -v
git push -u origin main
The remote listing confirms which address Git will use. The first push sends the branch to GitHub, and the -u option records its upstream so later pushes on this branch can use git push without repeating the remote and branch names.
GitHub command-line authentication does not accept your account password for Git operations. Never paste a token into a shared terminal transcript or commit it to a repository.
HTTPS and SSH address the same remote repository. HTTPS can prompt a credential helper to store an authorized token, while SSH proves access with a private key on your computer and its matching public key registered with GitHub. Keep the private key private and protect it with a passphrase.
A credential manager can store HTTPS credentials outside the repository. If you use SSH on more than one computer, each computer needs an authorized key. Revoke a token or remove a key from GitHub when it is no longer needed.
If the GitHub repository already has a README or other files, clone it into a new folder and work from that copy. Avoid initializing a second local history and pushing over a remote that already has its own first commit.
Step 6: Verify the GitHub page and continue with a branch
Open the repository page and confirm that README.md and the commit message appear. For a follow-up change, work on a separate branch and push it.
Compare the topic branch with a base branch such as main. Review the changed files and checks, discuss requested updates, then merge when the change is ready. A pull request keeps that review attached to the branch, so later commits to the same branch update the proposal.
Before opening a pull request, check that the base is the branch you intend to update and that the compare branch contains only the proposed change. After reviewers request an edit, commit it on that source branch and check the updated diff before merging.
A merge conflict means two sets of changes affect the same lines or Git cannot combine their histories automatically. Read the conflict markers in the affected file, keep the intended result, remove the markers, then stage and commit the resolution. A pull request can be updated by pushing another commit to its source branch.
Common GitHub Setup Problems and Fixes
Common first-push problems come from a mismatch between local state, remote state, or authentication. Check the exact error before changing repository history.
| Symptom | Likely cause | What to check |
|---|---|---|
| “Author identity unknown” | Git name or email is not configured | Set user.name and user.email, then retry the commit |
| “src refspec main does not match any” | No local commit exists, or the branch has another name | Check git status and the branch name |
| “remote origin already exists” | A remote named origin is already configured | Run git remote -v. Use git remote set-url origin URL if the address is wrong |
| “Updates were rejected” | The remote has commits absent from the local branch | Inspect the remote history and integrate it before pushing |
| Authentication failed | Invalid or missing HTTPS credential or SSH key | Use a supported credential manager, token, or registered SSH key |
When a push is rejected because the remote contains a README or another commit, fetch or pull that history and inspect the result. Avoid force-pushing, which can replace remote history.
If you accidentally initialized Git in the wrong directory, stop before adding files. Use pwd and git status to identify the repository root, then move the intended project into the correct folder rather than staging unrelated files with git add .
For a command reference beyond this first workflow, see CodeForGeek’s guide to Git commands. GitHub’s Hello World tutorial demonstrates the repository, branch, commit, pull request and merge path in the web interface. If you are publishing a Next.js project after the push, the site’s Next.js deployment guide follows that next step.
Conclusion: Keep Local History and GitHub in Sync
The next step is to use a topic branch when you want review before merging.
For deeper reading, start with the official Pro Git book, GitHub’s Hello World guide, and the GitHub Docs page on pull requests. They cover Git concepts, the beginner workflow, and review in more detail.
FAQ
These quick answers clarify the terms and first-push choices beginners often ask about.
Is GitHub the same as Git?
No. Git is version control software that records project history. GitHub hosts Git repositories and provides collaboration features such as pull requests.
Do I need Git installed to use GitHub?
No for basic browser uploads and edits. Install Git to manage project history and send commits from a local computer with Git commands.
Should I choose HTTPS or SSH for a GitHub remote?
Either can work. HTTPS pairs with a credential manager or personal access token, while SSH requires a key registered with GitHub. Choose the method you can configure and protect.
Why create a branch instead of committing directly to main?
A branch isolates a proposed change from the default branch. Pushing it lets you review the changes in a pull request before merging them.




