DEV Community

Cover image for Git and GitHub: A Comprehensive Guide
Otitoju Mercy
Otitoju Mercy

Posted on • Edited on

Git and GitHub: A Comprehensive Guide

What is Git?
Git is a distributed version control system used to track changes in files, typically source code. It allows multiple developers to collaborate on a project by managing and recording changes over time. Git is widely used because of its speed, efficiency, and flexibility, making it an essential tool in modern software development.

What is GitHub?
GitHub is an online platform for storing, sharing, and collaborating on code using Git. With GitHub, you can store your code online, collaborate with other developers, and track changes over time, all in one place.

Basic Git Command

Here are some basic Git commands:

  • git init: Start a new Git repository in your current directory.
  • git clone <repository-url>: Download an existing repository to your local machine.
  • git add <file>: Stage changes to be included in the next commit.
  • git commit -m "message": Save staged changes with a commit message.
  • git status: Show the current status of your working directory and staging area.
  • git log: View the history of commits.
  • git push: Upload local commits to a remote repository (like GitHub).
  • git pull: Download and merge changes from a remote repository.
  • git branch: List all branches or create a new branch.
  • git checkout <branch>: Switch to a different branch.
  • git remote add origin [repository link]: Connect the local folder to the GitHub repository.
  • git push -u origin main: Push code to the 'main' branch on GitHub.

Before the end of the blog will be able to set up git on window's, creating a respository , making commits, pushing and pulling.

Setting up Git on Windows.

Install Git: Download from https://git-scm.com/book/en/v2/Getting-Started-Installing-Git website, run it, and follow the installation instructions.

Configuring Git:After installation,Open Gitbash as ADMINISTRATOR,and run the following Git command :

  • git version -TO KNOW THE GIT VERSION.
  • git status -TO KNOW GIT STATUS IF THERE IS ANY PENDING CHANGE.
  • git config --global user.name githubusername -LIKE LOGIN USERNAME.
  • git config --global user.mail githubemail -LIKE LOGIN EMAIL ADDRESS
  • mkdir filename -TO CREATE FOLDER IN FILE EXPLORER
  • cd filename -TO ENTER INTO A PARTICULAR FILE NAME
  • git init -TO MAKE A FOLDER A GIT REPOSITORY SO AS TO HAVE ACCESS TO GIT COMMANDS
  • code . -TO TRANSIT INTO VS CODE

Image description

  • This takes you to Visual Studio Code.
  • Click on the icon to create a file.
  • Name the file index.html.

Image description

  • Paste your HTML code into it,
  • Click on the three dots at the top,
  • Click on Terminal, then New Terminal.

Image description
In the terminal type the following command;

  • git add <file>: Add a file to the staging area.

  • git status: Show the status of changes.

Image description

Creating a Repository.

Repository (often abbreviated as "repo")serves as a structured place where various types of digital resources are stored, managed, and accessed Creating a repository on GitHub is a straightforward process. Here’s a step-by-step guide to get you started:

  • Go to GitHub,Log in to your GitHub account.
  • Click the "+" icon in the top right corner of the page. Select "New repository" from the dropdown menu.

Image description

  • Repository Name: Enter a name for your repository.
  • Description: (Optional) Provide a brief description of your repository.
  • Private or Public: Choose people that can see this repository.
  • Add a README file.

Image description

  • Click the "Create repository" button at the bottom of the page.

Image description

Making a Commit.

A commit is a record of changes made to the files in a repository. It represents a snapshot of the project at a particular point in time. Making a commit in Git involves a few straightforward steps. Here’s a step-by-step guide to help you through the process:

  • Use the git commit command followed by the -m flag and your commit message in quotes.

Image description

Pushing and Pulling.

Pushing is the process of uploading your local commits to a remote repository. This updates the remote repository with changes made locally. Here is the command used for pushing changes:

  • Copy The Link Of the remote Repository.

Image description
Issue a git push command using url of the remote repository:

Image description
If you are Pushing for the first time, you will be taken to GitHub sign-in and authorization.

Image description

Image description

  • Go to GitHub, to see the recent Push

Image description

  • Type git commit -m "adding readme.md", To check the readme file, go to your GitHub account, refresh, and click on readme.md to see the message earlier typed when you created the readme.md file.

Image description

  • To edit click on the edit icon after editing your text, click on Commit Changes

Image description

Pulling in Git is the process of updating your local repository with changes from a remote repository .This command helps keep your work synchronized with your team's changes, ensuring you're always working with the latest version of the project.

Image description

"Congratulations on successfully setting up Git on Windows! You've mastered the essentials of version control by creating a repository, making commits, and learning how to push and pull changes. This is a solid foundation that will serve you well in your development journey. Great job!"

Top comments (0)