A Quick Start to Git and GitHub

A Quick Start to Git and GitHub


Check out My Repository



Table of Contents

Introduction
Setting Up Git

  • Installation
  • Configuration

Creating a Repository

  • Initializing a Repository
  • Cloning a Repository

Basic Git Commands

  • Checking Status
  • Adding Files
  • Making Commits
  • Pushing Changes
  • Pulling Changes



Introduction

Git and GitHub have become essential tools for developers worldwide. Git is a version control system that tracks changes in source code, while GitHub is a web-based platform for hosting Git repositories. Mastering Git and GitHub is crucial for modern software development and devops. This guide will walk you through setting up Git, creating a repository and using the basic commands like commits, pushing and pulling.



Setting Up Git



Installation

To get started with Git,

  • Choose your local computer OS. For windows, choose the appropriate for your configuration and install.

Image description

  • Sign up on GitHub to register a GitHub account.



Configuration

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.

Image description

  • Configure Username. Run the command below personalizing the username and press enter.
    git config --global user.name "Your GitHub username"

  • Configure email. Run the command below personalizing the email and press enter.
    git config --global user.email "your github email address"

Image description



Creating a Repository

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

  • Run this command to create a new directory called gitlab.
    mkdir gitlab
  • Run the command below to change directory
    cd gitlab



Initializing a Repository

To create a new repository, run the following command
git init
This will initialize empty git repository in the local directory.

Image description

  • To open a new visual studio code, run the following command and press enter.
    code .

Image description



Basic Git Commands

You need to have a code before you can carry out any other command.

  • On the Visual studio code create a .html file. On the menu, click on the 3 dot select terminal and then new terminal.

Image description

  • On the terminal, run git commands like check status, add, commit, push and pull.



Checking Status

git status



Adding Files

Add your file to the staging area.

git add filename

git add .

Image description



Making Commits

Commits are snapshots of your project at a given point in time. Once your changes are staged with the add command, commit them with a message:

git commit -m "Your commit message"

Image description



Pushing Changes

Pushing command sends your commits to a remote repository, like GitHub. Hence, the remote repository has to exist first before a push command can take effect.



Creating Remote Repository GitHub

  • go github.com and sign in
  • click on + to add new repository

Image description

  • Give it a name.
  • choose public or private
  • Add README file for your documentation
  • Click create repository

Image description

  • go to code and copy the repository url.

Image description

  • connect the repository to the local machine. use the following command.
    git remote add origin repo url

Image description

  • Push changes
    git push origin master

Image description

  • sign in to GitHub when prompted and authorize git ecosystem. This is only applicable when you are pushing for the first time.
  • Go back to GitHub and notice the file is now in GitHub.

  • add a readme file on visual studio code. Afterwards do git add, git commit and git push.

Image description

Image description



Pulling Changes

Pulling fetches and merges changes from the remote repository to your local repository.

  • Edit any of the file on GitHub, commit changes

Image description

  • On your terminal, type the pull command below and notice the changes now reflect.

git pull origin master

Image description

Check out My Repository



Source link
lol

By stp2y

Leave a Reply

Your email address will not be published. Required fields are marked *

No widgets found. Go to Widget page and add the widget in Offcanvas Sidebar Widget Area.