DEV Community

Yusuf Isah
Yusuf Isah

Posted on • Originally published at yuscode.hashnode.dev

Chapter 3 - GitHub

Introduction

GitHub is the world's leading software development platform, where millions of developers, engineers, and innovators collaborate, share, and build on each other's work. Founded in 2008, GitHub has transformed the way we develop, manage, and deploy software. With over 100 million repositories and 40 million users, GitHub is the go-to destination for open-source and private projects, from small startups to large enterprises.

GitHub's collaborative platform enables users to:

  • Host and manage code repositories.

  • Track changes and collaborate on projects.

  • Share knowledge and learn from others.

  • Build and deploy software with ease.

Table of Contents

Differences Between Git and GitHub

Git and GitHub are often used interchangeably, but they're not the same thing. Understanding the difference is crucial for effective version control and collaboration. Below are some key differences between them:

Git GitHub
Git is installed locally on your system GitHub is hosted on the web
Provides a command-line interface for managing code repositories GitHub is a graphical user interface
Git is a free and open-source version control system GitHub offers a mix of free and paid options

Creating Your GitHub Repository

  • First, create your GitHub account. It is a simple and straightforward process. Next, navigate to the top right corner of your GitHub page and click on the plus [+] sign.

Image description

  • Click on New repository from the drop-down menu. Next, give your repository a name, e.g., countries. Next, give your repository a description. Leave your repository as public; private is for paid subscribers. Finally, click on create repository.

  • Copy the address of your GitHub repository. It should look similar to this:

Image description

  • Go back to your countries directory on your local machine. Use the git log command to see the previous commits you want to push to GitHub.

  • To push your commits to GitHub, first create a remote using the command git remote add origin "address of your GitHub repo". Let's breakdown this command to understand what it is doing:

    • git remote: This command is used to manage remote repositories, which are versions of your project stored on a server or another location.
    • add: This sub-command adds a new remote repository to your local Git configuration.
    • origin: This is the name given to the remote repository. "Origin" is a conventional name for the primary remote repository, but you can use any name you like.
    • address of your GitHub repository: This is the URL of the remote repository on GitHub. For example, if the URL of your GitHub repository is https://github.com/yusbuntu/countries.git, then your git remote add command would look like this:

      git remote add origin https://github.com/yusbuntu/countries.git
      
  • Next, push your commits to your GitHub repository. To do this, first run:

    git branch -M main
    

Then run:

sh git push -u origin main

NB: If you're using the default branch name (usually "master"), then the second code above will be:

git push -u origin master
Enter fullscreen mode Exit fullscreen mode
  • The command above will prompt you for your GitHub username and password. Password authentication is disabled on GitHub, so you will have to generate a personal access token instead. To generate your token, follow the steps below:

    • Click on your profile picture at the top right corner of your GitHub repository.

Image description

* Click on `settings`.

* Scroll down and click on `Developer settings` on the left side bar.

* Click on `personal access tokens`'.

* Click on `Tokens (classic)`.

* Click on the `Generate new token` button.

* Select `Generate new token (classic)`.

* Input what you want to use the token for, e.g., access.

* You can leave the expiration date at 30 days.

* Under `select scope`, click on `repo`.
Enter fullscreen mode Exit fullscreen mode

Image description

  • Scroll down and click on the Generate token button.

  • Make sure to save the generated token somewhere.

  • Use the token as your password when you want to push your commits to GitHub from your local machine.

  • Go back to your Github page and click on your profile picture. Next, click on Your repositories. Finally, select the repository you just pushed into to see the changes you made.

Conclusion

GitHub is more than just a platform for hosting code repositories – it's a vibrant ecosystem that fosters collaboration, innovation, and growth. By leveraging the power of remote repositories, and mastering the art of pushing commits, developers can unlock a world of possibilities.

Feel free to comment and share this article. Please follow my blog for more insights on Git and GitHub!

Top comments (0)