Connecting to a Remote Repository (GitHub, GitLab, Bitbucket)
3. Pushing Your Local Repository to the Cloud
So, you've initialized your local repository and made some commits. Great! But your code is still only on your computer. To share it with the world (or just your team), you need to connect it to a remote repository, typically hosted on services like GitHub, GitLab, or Bitbucket. These platforms provide a central location to store your code, collaborate with others, and track issues.
Before you can push your local repository, you'll need to create an account on one of these platforms and create a new, empty repository. Give it a name and a description, and be sure to choose whether you want it to be public or private. Once you've created the remote repository, you'll be given a URL that you'll need to use to connect your local repository.
Back in your terminal, use the `git remote add origin [your_repository_url]` command to link your local repository to the remote one. Replace `[your_repository_url]` with the URL you copied from GitHub, GitLab, or Bitbucket. The `origin` is a shorthand name for your remote repository; you can call it something else, but `origin` is the standard convention.
Finally, it's time to push your local changes to the remote repository. Use the command `git push -u origin main`. This command pushes your local `main` branch (or `master` if your repository is older) to the remote repository. The `-u` flag sets up a tracking connection between your local and remote branches, so you can use simpler commands like `git push` in the future. Depending on your setup, you might be prompted to enter your username and password for the remote repository.