Now that you have connected a remote to your local Git repo, you're ready to push your code to GitHub:
git push -u origin master
Note: Depending on your setup, this command may prompt you for your GitHub username and password first. If you need help getting set up with Git, consult the Version Control with Git and GitHub course.
Info: The -u option is an argument to the push command that sets the remote you specify, in this case origin, and a branch, in this case master, as the default upstream remote and branch. If you use the -u option, you won't have to specify the remote and the branch anymore for subsequent pushes. Following this setup, you will only need to run git push to send your updated code to your GitHub remote.
Check the Push to GitHub
If all went well you should see feedback from Git in your CLI that reads similar to the output below:
Enumerating objects: 122, done.
Counting objects: 100% (122/122), done.
Delta compression using up to 4 threads
Compressing objects: 100% (119/119), done.
Writing objects: 100% (122/122), 2.11 MiB | 1.50 MiB/s, done.
Total 122 (delta 0), reused 0 (delta 0)
To https://github.com/martin-martin/python-labs.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
Congratulations, you have successfully pushed your local version-controlled code to a remote GitHub repository. Double-check whether it worked as expected by returning to the new repo you created in GitHub using your web browser and refreshing the page. You should see the labs project folders and the README.md file show up:
If you see your GitHub repository has filled up with the same files and folders you committed earlier to your local Git repository, then your setup is complete.
Always Push
From now on, every time you make a commit to your local Git repo, you should also push your code to GitHub using git push. Every time you push code to GitHub, the site awards you with a green dot on your profile's Contributions heatmap:
For some employers, GitHub is considered as an alternate portfolio, and the contributions heatmap can be a way to show that you code on a regular basis.
Practice: Green Dots Every Day
Aim to have a green dot just about every day of every week moving forward in order to train your skills and build on your GitHub portfolio.
Use the code you push to your GitHub repo to share code examples or ask and answer questions on Discord.
If you want to dive deeper into using Git and GitHub for version control, check out the additional course on Version Control with Git and GitHub that goes into much more detail.
Summary: How to Push to GitHub
git push -u origin masterwill push local files to your connected remote and under the master branch- Read the feedback from Git in your CLI to confirm the push worked correctly
- It is good practice to always push your code regularly