I often forget how to upload a new project to a remote Git repository because that is rarely done. Thus I need to summarise essential steps of this operation in my blog so that I could have look it back. So here is how you can also do it.
- First create a remote Git repository in your GitHub or Bitbucket account. You can create a repository in GitHub from the link, or in Bitbucket from the link (remember logging in before clicking these links).
- After creating a remote repository, copy the clone URL. This would look something like:
- email@example.com:<username>/<project-name>.git (based on GitHub) or firstname.lastname@example.org:<username>/<project-name>.git (based on Bitbucket), if you decide to use SSH port.
- https://github.com/<username>/<project-name>.git (based on GitHub) or https://<username>@bitbucket.org/<project-name>.git (based on Bitbucket).git, if you decide to use HTTPS port.
- Next go to the local directory where you have created your project and run the command git init . This would make your project being tracked by git.
- In addition, you have to map the newly created Git repository in your local directory to the GitHub/Bitbucket remote repository.
git remote add origin [alias-for-this-url] <the-clone-URL-as-described-in-the-step-2> .
- Finally, you can make some modifications, add these changes and push them your remote repository.
That’s it. To test the mapping, type the command git remote -v . This should list your remote repository URLs.
We often encounter a “Permission denied” error, while trying to do a git push , it means that, the server has rejected your connection. To fix this you will have to add your ssh key to your GitHub account. The steps for adding the ssh keys are well explained here or there.