Connect to GitHub
In this part, you will connect the local repository from Part 3 to GitHub, upload your commits, bring remote changes back down, and clone the same project into a new folder.
What We Will Do
- Create a GitHub account and repository
- Connect the local repository to a GitHub remote
- Push local commits and pull remote changes
- Clone the same repository into another folder
Requirements
Before you copy the commands
Replace these placeholders with your own values each time you see them:
YOUR-USERNAME: your GitHub username
- my-first-repo: your repository name on GitHub
Example:
https://github.com/alice/my-first-repo.git
30-second concept map
Before the labs, keep these three ideas in mind:
- remote: a saved connection from your local repository to another repository URL
- origin: the default name Git usually uses for the main remote
- push, pull, clone: send commits up, bring commits down, or copy the whole repository into a new folder
Authentication note
GitHub no longer accepts your account password for Git operations over HTTPS. If Git asks for credentials during git push or git pull, use your GitHub username and a Personal Access Token instead of your password.
Lab 1: Create a GitHub Account
If you already have a GitHub account, you can skip this lab and go straight to the repository setup.
Sign up for GitHub
- Go to github.com
- Click Sign up
- Enter email, password, and username
- Complete email verification
Lab 2: Create a GitHub Repository
This lab creates the remote repository on GitHub. Keep it empty so you can push your existing local project into it.
Make a new repo
- Click the + button on GitHub
- Select New repository
- Repository name:
my-first-repo
- Choose Public
- Click Create repository
After creation, GitHub shows commands for connecting an existing repository. In this post, you will run the same idea step by step so you can see what each command does.
Ready. Press Replay to run the scripted session.
Lab 3: Connect the Remote
This lab links your local repository to the GitHub repository you just created.
Check your starting point
Make sure you are inside the project from Part 3 and that it already has a commit.
Ready. Press Replay to run the scripted session.
Move to the local project
The next command adds a remote named origin. That name is only a label, but it is the standard label Git tutorials use for the main remote.
Ready. Press Replay to run the scripted session.
If git remote -v shows two origin lines, the connection is ready. One line is for fetching, and the other is for pushing.
Lab 4: Push Code
This lab uploads your local commits to GitHub for the first time.
Push
Use -u on the first push so Git remembers that your local main branch should track origin/main. After this setup, plain git push is usually enough.
Ready. Press Replay to run the scripted session.
Check on GitHub
- Open the repository on github.com
- Open README.md to verify the content
- Review the file list
If the files appear on GitHub, your local repository and remote repository are now connected correctly.
Lab 5: Edit on GitHub, Then Pull
This lab shows the opposite direction: you will make a change on GitHub first, then bring that change back to your computer.
Edit on GitHub
- Click README.md
- Click the pencil icon (✏️)
- Edit content:
# My First Project
Edited on GitHub!
- Click Commit changes...
- Write a commit message
- Click Commit changes
Pull locally
git pull fetches new commits from the remote and then updates your current branch with them.
Ready. Press Replay to run the scripted session.
Verify locally
The file on your computer should now match the file you edited on GitHub.
Ready. Press Replay to run the scripted session.
Lab 6: Practice Clone
This lab creates a completely new local copy from GitHub. Use clone when you want to download an existing repository instead of connecting one you already have.
Prepare a folder
Ready. Press Replay to run the scripted session.
Clone
Notice that git clone creates a new folder named after the repository.
Ready. Press Replay to run the scripted session.
Inspect the cloned project
Ready. Press Replay to run the scripted session.
At this point, you have two local copies of the same project: the original my-first-git-project folder and the cloned my-first-repo folder.
Key Commands Recap
| Command |
Description |
git remote add origin URL |
Connect a remote |
git remote -v |
Verify remotes |
git push -u origin main |
Push code |
git pull |
Get remote changes |
git clone URL |
Copy a repository |
Troubleshooting
"fatal: Authentication failed"
Fix:
- Do not use your GitHub account password for Git operations over HTTPS
- Create a Personal Access Token on GitHub and use that token when Git asks for a password
- If you already saved the wrong credential, clear it from your credential manager and try again
"fatal: repository not found"
Fix:
- Verify that the repository exists on GitHub
- Check that you replaced
YOUR-USERNAME with your real GitHub username
- Copy the repository URL again from GitHub and re-run
git remote add origin ...
"rejected: non-fast-forward"
Fix:
# First, bring your main branch up to date
git pull --rebase origin main
# Then push again
git push origin main
"fatal: not a git repository"
Fix:
cd correct_folder
git status
Practice Checklist
Next in the Series
👉 Git Series Part 5: Branches and .gitignore
💬 댓글
이 글에 대한 의견을 남겨주세요