Git and GitHub Basics
GitHub and Pull Requests
In this lesson you will
- Connect a local repository to GitHub
- Push and pull changes
- Explain what a pull request is and how a review works
Introduction
So far everything lives on your own computer. GitHub keeps a copy online, which gives you a backup and lets other people see, review and contribute to your work.
The simple explanation
A remote is a copy of your repository somewhere else. You push to send commits there and pull to bring new ones back.
Connect to GitHub
- Create a free account at github.com.
- Click New repository, give it a name, and create it (leave it empty).
- Copy its address, then connect and send your work. Replace the address with your own:
Terminal
# link your project to the online copy; "origin" is the usual name
git remote add origin https://github.com/your-name/my-project.git
# send your main branch up and remember the link
git push -u origin mainGitHub will ask you to sign in. Use the method it recommends, such as a browser sign-in or a personal access token, and never share that token.
Push and pull
Terminal
# send new commits to GitHub
git push
# bring down commits made by others (or from another computer)
git pullPull before you start working so you begin from the latest version.
Quick quiz
Which command sends your new commits to GitHub?
Pull requests
A pull request (PR) is a request to merge your branch into another one, usually main. It is where teammates discuss and review the change before it is combined. The usual flow is:
- Create a branch and make your commits.
- Push the branch:
git push -u origin add-footer. - On GitHub, click Compare and pull request, write what you changed and why, and submit it.
- Teammates comment and may ask for changes. You commit more changes to the same branch and they appear in the PR.
- When it is approved, the PR is merged and you can delete the branch.
Contributing to other people's projects
On GitHub you can fork a public project to make your own copy, make a change there, and open a pull request back to the original. This is how many people contribute to open source software. Read the project's contributing guide first and be polite and patient.
Try it yourself
Create a free GitHub account and an empty repository. Push the project you made in the earlier lessons. Then make a branch with a small change, push it, and open a pull request against main for yourself.
Summary
- A remote such as GitHub holds an online copy of your repository.
git pushsends commits andgit pullbrings new ones down.- A pull request proposes a branch for review before it is merged.
Lesson complete
+20 XP
Nice work. Keep going while it is fresh.
Sources and further reading