DEV Community

Cover image for Introduction to Github
Oluwademilade Ala
Oluwademilade Ala

Posted on

Introduction to Github

Have you ever wondered how to store or keep track of your project versions as a developer or software engineer? How to present your project to clients or collaborate with other developers?

We will go over how to combine Git with GitHub, one of the web platforms that developers use the most to share code and work in teams.

In this article, we'll cover the following to simplify how Git and Github works:

  • Difference between Git and Github
  • Create a Github account
  • How to get started with github and git
  • Create your first Github repository
  • Clone a Github project
  • Make a github commit
  • Github Desktop and Github CLI

Let us begin

What is Github

Github is a platform for developers to create, manage, store and share their code. Github also serves as a hosting service you can use to collaborate on projects and share files.

According to Github resources, It's not just developers who build on GitHub. Fortune 500 companies, small teams, project managers, and college professors all use GitHub to do their best work, in one place.

Why Github

Github is widely used among millions of developers to collaborate and work together, and the numbers keep increasing.

As a result, an increasing number of companies are expecting new workers to know how to use GitHub and Git. Therefore, these are the skills to have if you are looking for a job as a developer.

The interface also makes it easy for users to oversee other projects like documentations,research papers, grant proposals etc. Anyone can register and own a public repository on Github. It also helps businesses manage their team members and security.

Git vs Github

According to FreeCodeCamp, Git was developed in 2005 by Linus Torvalds as open source software for tracking changes in a distributed version control system.

You'll need an approach for tracking or documenting your code when working on a project. This helps with organization of your work and allows you to monitor the changes you have made. Git allows you to do this.

Git is a tool for managing different versions of source code updates that are afterward transferred to files in a Git repository, while Github is a location where copies of a Git repository can be uploaded.

How to get started with github and git

1. Install Git
You can check if you have git installed already by typing git version in your terminal.
To open your terminal in windows, click on the windows button and search for terminal or cmd. For mac, press the command and space button, then search for terminal.

search-terminal

If you don't have git installed, you can download git with this link and then choose the operating system you want to use.

2. Create a Github account
To register an account on github, click on this link where you'll be required to fill some information, make sure to set a strong and unique password.

3. Set up Git

  • set your username and email
  • Open your terminal and type the following commands
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
Enter fullscreen mode Exit fullscreen mode
  • To confirm that you have set them correctly, enter the commands:
git config --global user.name
git config --global user.email
Enter fullscreen mode Exit fullscreen mode

You should have your selected name and email as the output

4. Create and edit your various files locally

code in local machine

5. Create a Github repository
You can create a github reposistory by visiting github.

  • Register by inputing your email and creating your password

github website

github-register

  • After registering, select the Repositories tab

github-repositories

  • Select the add NEW repository button to create a new repository

github-add-new-repo

  • Enter your name, choose whether to make the repository public or private. Anyone that is one the internet can see a public repository while you choose who can see and commit to a private repository.

  • Choose to add a README file where you can write a long description of your project.

  • Select the Create repository button to create your first github repository.

github-create-first-repository

simple-right

Clone a github project

After creating a github repository, navigate back to the Repositories tab. Follow these steps to clone a Repository to your local machine.

  • Copy the Repository URL

copy-url

  • Open your terminal
  • Navigate to the directory where you'd like to place your project folder
  • Run git clone followed by your Repository URL
git clone https://github.com/"your-username"/your-repository.git
Enter fullscreen mode Exit fullscreen mode
  • Navigate into the cloned repository

cd your-repository

  • You can open the Repository with any IDE (Integrated Development Environment) of your choice.

Make a github commit

Once you've added your files or made edits to your project files, you can save your changes on git by adding commits.

Commits allow Git to track changes locally on your device. This enables you to keep a history of changes to your files, allowing you to revert to a previous version if needed.

You can follow these steps to make a commit:

  • Open your project terminal

terminal

  • Stage the changes
git add .
Enter fullscreen mode Exit fullscreen mode
  • Commit your changes
git commit -m "First Commit"
Enter fullscreen mode Exit fullscreen mode

The -m flag in the git commit command stands for "message." It allows you to provide a commit message directly from the command line.

  • Push the changes to Github
git push origin main

Enter fullscreen mode Exit fullscreen mode

If the origin is not set to main, adjust the command accordingly.

Github Desktop and Github CLI

Github Desktop is a GUI (Graphical User Interface) application that simplifies working with Git and Github.

The CLI offers a more direct and flexible way to perform Git operations Vishwas Acharya (GitHub Desktop vs Command Line: Which is Right for You?)

Both GitHub Desktop and GitHub CLI provide special benefits. GitHub Desktop is a great option for beginners and those who prefer a visual approach because of its user-friendly graphical interface, which makes interacting with Git and GitHub easier. GitHub CLI, on the other hand, gives users the command-line's flexibility and control, making it perfect for expert users and those who want to automate and script their GitHub activities. They are both made to help you be more productive and optimize your version control procedures.

In conclusion, Git and GitHub are strong tools that complement one other to facilitate collaborative development and version control. Git is a distributed version control system that facilitates version control, change tracking, code version management, and effective teamwork. By offering a repository hosting platform, encouraging teamwork, and including extra capabilities like pull requests, issue tracking, and continuous integration, GitHub expands upon Git.

Top comments (0)