Learning How to Git: Push Commits to Remote Repository
Yesterday, we have talked about the creating commit in Git. But, those commit only available on our local repository or our PC. So, today we are going to push our commit to the Git repository.
A repository is basically the directory where we initialize the Git to track the project. However, what we have so far is the local repository. What about the remote repository? As the name suggests, it is basically a repository on the internet or in a certain network. Hosting our project in a remote repository means that we able to work with other people or collaborators with our source code.
There are several Git repository hosting service available, some of the famous services consist of GitHub, BitBucket, Gitlab, and so on. In this example, we are going to create one in GitHub.
Creating Remote Repository
Creating new Git repository in GitHub is as easy as 1–2–3. So, you can just follow what the forms need you to fill and choose. And you finally select “Create Repository”. Voila! Now you already create your first remote repository.
Push Our Local Repository to Remote Repository
Now, since we have already created a repository on our local we can push it to the remote. GitHub already presented us with an easy instruction.
If you have already understood how to generate SSH and store it into GitHub, you can easily use the SSH link. However, if you are a newcomer, I suggest you use the HTTPS link for now. So all we need to do is to run
git remote add origin <repository-link> and push it using
git push -u origin master. Let’s try to do that.
Okay, so basically it says that we have pushed our local repository to the remote repository. If you realized, we will be prompted with username and password. That’s the drawback of using https because we need to provide our credential every time we push commits to the remote repository. For now, let’s bear with it. Now, if we checked the remote repository, it will show what we have so far.
Now, your code already hosted and can be accessed from the GitHub link.
Continuing from the previous story, today we have pushed our commit to the remote repository. For the next story, we will talk more about how to use SSH rather than HTTPS for easier Git usage. Hopefully, it’s helpful and thanks for reading.