Getting Started with Git and GitHub: A Beginner’s Guide

Getting Started with Git and GitHub: A Beginner’s Guide


Introduction

Git and GitHub have become indispensable tools for developers, enabling seamless collaboration, version control, and code management. Whether working solo or on a team, mastering these tools is a crucial step in your development journey. This guide will walk you through setting up Git, creating a repository, and performing essential commands.


1. What is Git and GitHub?

Git: A distributed version control system that tracks changes to files over time.

GitHub: A platform for hosting Git repositories, enabling collaboration, and project sharing.


2. Prerequisites

A computer with Git installed. (Download from Git’s official site).

A GitHub account (Sign up at GitHub).

3. Setting Up Git

Install Git:

Git download page

After installing Git, initialize your git in git bash and configure your username and email. These details will be associated with your commits.

  • On your local computer task bar search for git bash and run as administrator.

Configure Git: Open a terminal and set your username and email:

bashCopy codegit config --global user.name "Your Name"
git config --global user.email "your-email@example.com"

Verify Installation:

Creating a Repository

A Git repository is where your project files and their revision history are stored.

Create a Directory

  • using a Linux code, we want to Run this command to create a new directory gitlabprojects

  •     mkdir gitlabprojects
    
  • Run the command below to change to the new directory created.

  •     cd gitlabprojects
    

    Initializing a Repository

    To initialize a new repository, run the following command

      git init
    

    This will initialize the empty git repository in the local directory.

  • for confirmation if it has been initialized go to “Document” on your local machine.

    Pushing to GitHub

    1. Link Local Repository to GitHub:

       git remote add origin <git remote add origin https://github.com/danielSamule/my-repo-cloud.git>
      

  • the The next thing we will do is create a file and push that file to the remote depository to be sure the link is functional. We will still be using some Linux commands. We can actually run it manually with VScode, but we will still use git bash to get familiar with the interface.

    The readme file has been created, we can write some things in the file using the statement nano

    •     nano readme.md
      

to be sure the statement was made and injected we will be using “cat” statement

  •     cat readme.md
    

    Add Files to the Repository: using the code below

      git add README.md
    

adding to the branch master you input this code

  •     git status
    

Making Your First Commit

  1. Add Files to the Repository:

Commit the File:

git commit -m "adding a readme file"

Push Changes:

git push -u origin master

Pulling Changes

  • Fetch and integrate changes from the remote repository:

    What is git pull?

    The git pull command fetches and integrates changes from a remote repository into your local working directory. It’s essentially a combination of two commands:

      git pull origin main
    

Conclusion

With Git and GitHub, you unlock the power of version control and collaboration, making your development workflow more efficient and reliable. Mastering these tools not only boosts your productivity but also prepares you for collaborative projects in the tech industry.