How to link the commits to Git hosts

It may help refresh your concepts on version control before starting this Answer.

In software development, connecting local commits to Git hosts such as GitHub is vital for maintaining a record of contributions. We must establish this connection, which enables us to synchronize our local commits with Git host repositories. By following these steps we, as developers, can showcase our contributions and keep a history of changes within the project’s online repository.

widget

To fully utilize the potential of version control, we must link our commits to our own Git hosts (GitHub, GitLab, etc). This Answer is a guide to establishing this connection and making us display our contributions in our own Git host repositories.

Steps

The following are the steps to link commits to Git hosts.

Cloning the repository

  1. Enter the following commands in the terminal:

git config --global user.name "Your Username"
git config --global user.email "Your Email"
git init && git remote add remoterepo "Repository Link"

These set up our username and email for our Git identity.

  1. Create a repository on GitHub. This can be done by logging in to our Git host account, navigating to the repository creation page, and following the instructions. In the case of GitHub, navigate to the following button:

widget

Pushing the repository

Once the repository is created, clone it with the following commands:

git clone "Repository"
cd "Repository"
  1. Create changes (adding a new file) with this command:

touch sample.txt
  1. Push the repository on GitHub:

git remote -v
git add .
git commit -am "Your commit message"
git push

In the last command, we’ll be asked to input our username and password for authentication. We’ll use our access token for the password. Details of getting this token can be seen here.

Live demonstration

Here we can see a terminal that we can use to execute the command we had gone through above.

Below is a list of commands that we covered above. We can use these commands in the terminal to understand how to link commits to Git hosts.

git config --global user.name "Your Username"
git config --global user.email "Your Email"
git init && git remote add remoterepo "Repository Link"
git clone "Repository Link"
cd "Repository Name"
touch sample.txt
git remote -v
git add .
git commit -m "Your commit message"
git push

Note: Replace "Your Username" and "Your Email" with your username and email respectively. Also, replace "RepositoryLink" with the repository URL you aim to push. Also, replace "Repository Link" with your own git repository link and replace "Your commit message" with whatever commit message you want to include.

After the push command, please enter your personal access token from your GitHub profile instead of the password.

Follow the steps below to establish a commit to the Git host in this terminal:

Terminal 1
Terminal
Loading...

After pushing, visit the repository. We should see our commits in the repository history linked to our account.

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved