Getting started with Git and GitHub.

What is Git?

Git is software that runs on your computer and manages your files. Free and open-source version control system. It lets you track changes you make to your files over time.

What is GitHub?

GitHub is an online hosting service for Git repositories. Allows collaboration.

Repository- project/folder. The folder where your project is.

Install Git & Create a GitHub account.

Git Architecture

What is a branch in git?

The branch is used to keep your changes until they are ready.

You can do your work on a branch while the main branch(master) remains stable. After you are done with your work, you can merge it into the main branch.

Commands in Git

Demo on Git

Let us implement some git commands on git using git bash.

  1. Check the version of git

git -- version

  1. Configuring Git.

    Replace USERNAME with the username that you created on GitHub

    Replace EMAIL with your email address

    git config --global user.name "USERNAME"

    git config --global user.email "EMAIL"

  1. check if configured

git config --list

  1. Create a directory "gitdemo" in your local machine

mkdir gitdemo

  1. Move to the "gitdemo" repository

cd gitdemo

  1. Initialize your git repository

We need to tell git this is a git repository.

git init

  1. Create a file called test.txt in the folder gitdemo, write something and save it.

  1. Check the status of your repository.

git status -to find out what is happening.

  1. Add the "test.txt" file created to make a commit.

git add test.txt

git add .

Check the status again.

  1. Commit the changes with a short message.

git commit -m " YOUR MESSAGE HERE"

Make changes to the file and save it again.

  1. View the changes

git diff

  1. Create a remote repository.

  1. Copy the link

  1. Connect your local repository to the remote repository.

git remote add origin ...

  1. Push the file to the remote repository.

git push origin master

reload GitHub

Branching and Merging

Create a new branch

git checkout -b tbranch

check the branch you're currently using

git branch

make changes to test.txt file

check the status again

git status

Commit the changes and push

Check the differences between the branches

git diff master

Go back to the master branch

git checkout master

Merge the branches then push.

git merge tbranch

git push -u origin master

Cloning.

A clone is a full copy of a repository, including all logging and versions of files.

If you want to get a copy of an existing Git repository — for example, a project you’d like to contribute to — the command you need is git clone.

git clone <link here>

GREAT LEARNING!!