Now that you’ve successfully created the repository and set up a local instance, you have two options:
- Push your local repository to GitHub, making it accessible to the world.
- Clone the GitHub repository to your local machine, allowing you to work on it locally before pushing to GitHub.
If you opt for the latter, you’ll add files to the cloned instance locally, following the standard sequence of adding, committing, and pushing changes. We will delve into this procedure later in our course.
For the purpose of this chapter, our focus will be on how to push your local repository to GitHub.
Prerequisites:
- Ensure you have a GitHub repository already created.
- Verify that you’ve set up a local Git repository.
Connecting Your Local Repository:
-
Locate the repository you just created on GitHub. Click on “Code,” expand the dropdown menu, choose “HTTPS,” and copy the provided URL.
-
Open your local repository using a terminal window.
-
Execute the following command:
git remote add origin https://github.com/<your_user_name>/<your_repo_name>.git
Note: Replace<your_user_name>
with your GitHub username and<your_repo_name>
with the name of the repository you created. -
Now, push your local changes to the remote repository using the command:
git push -f origin HEAD
-
Head to your repository on GitHub. Refresh the page if needed. Can you spot your local content in the GitHub repository? Great! This command transfers your local repository’s contents to the GitHub repository, making your project accessible to the world.
Additional Notes:
- The
-f
flag in thegit push
command forces the push even if there are remote changes that haven’t been pulled. This is useful if you’re starting a new repository and haven’t made any changes remotely.
By following these steps, you’ll seamlessly integrate your local repository with GitHub. Now, your project is ready to shine on the GitHub platform. See you in the next chapter!
Course completed
Have an issue? Please provide specific feedback by reporting an issue.