Git and GitHub

What is Git ?

Git is a free and open-source distributed version control system. It keeps track of projects and files as they change over time with the help of different contributors.

Installing Git in Linux

Installing Git in Linux we can use below command:

sudo apt-get install git

You can check whether Git is installed and what version you are using by opening up a terminal, and typing the following command:

git --version

Setting up git

Now that you have Git installed, we need to provide our name and email address because Git embeds this information into each commit we do. We can go ahead and add this information by typing:

git config --global user.name "Your Name"
git config --global user.email "youremail@domain.com"

We can see all of the configuration items that have been set by typing:

git config --list

Different stages in Git

Every local repository has three different virtual zones. these are:

  1. Working Directory : This is the directory on your local machine where you create, edit, and delete files as part of your development process. Any changes made to files in this directory are considered to be in the working directory stage

  2. Stagging Area (index): The staging area is like a holding area where you prepare changes before committing them to the Git repository. Files that you want to include in the next commit are added to the staging area using the git add command.

  3. Commit Area : Once you have staged the changes you want to include in the next commit, you can create a commit.Commits are created using the git commit command.

Basic Git commands

clone : Bring a repository that is hosted somewhere like GitHub into a folder on your local machine.

add : Track your files and changes in git.

commit : Save your files in git.

push : Upload git commits to a remote repository, like GitHub.

pull : pull is used to fetch and download changes from remote repository to your local machine, the opposite of push.

git init # initialize local git repository
git add <file name> # add files to index
git status # check status of working tree
git commit # commit changes in index
git push # push to remote repository
git pull # pull latest from remote repository
git clone # clone repository into a new directory

What is GitHub

GitHub is a web-based platform built on top of the Git version control system. It provides a centralized location for developers to store, collaborate on, and manage their code repositories.

Branch

Branch is essentially a unique set of code changes with a unique name. Each repository can have one or more branches.

Repository

A repository is a collection of source code. A repository has commits to the project or a set of references to the commits.

Steps to push the projects into GitHub

git init # initialize local git repository
git remote add origin <repository_url>
git remote -v
git status # chcek status of working project
git add . # add files to index
git status 
git commit -m "message" # commit changes in index
git branch  # check the current branch
git push origin master # push to master branch