Git & Github

Git & Github

  • What is Git?
  • Feature of Git
  • Basic of how Git works
  • Basic Git Workflow
  • Github

What is Git?

Git is a version control system that keep tracking of changes to the file or setup files overtime so that you go back to the specific version later. Git is a distributed version control framework that is free and open source. Linus Torvalds, the developer of the Linux operating system kernel, created it in 2005.

Feature of Git

  • Track History
  • Free and open source
  • Supports non-linear development
  • Create backups
  • Scalable
  • Supports collaboration
  • Branching is easier
  • Distributed development

Basic how Git works

First and foremost, it is important to understand the 3 areas where you code lives inside git:

Untracked Area(working tree)

Working tree contains the files that you are currently working on. When you open the files for a project that is managed as a Git repository, you gain access to the Working Tree. In this stage doesn’t tracks the changes.

Staging Area

The staging area is like backstage in a theatre, i.e. this area contains all the added files that contain new/changed code, which is ready to be joined to the next commit. All new/changed files are first pushed to the staging area.

Committed stage(History)

It is also known as history area. In this we can track changes in the file with message.

stages area.jpeg

Basic Git Workflow

1.When you browse and work on files in your repository, you are on a working tree, and all of your files are untracked at first.

2.The files you want to record are then staged and moved to index.

3.The staged files are then committed and saved in the local repository.

4.When you're ready to make them public, add them to a remote repository hosting service such as Github.

Github

Github is an online platform that provides hosting services to the git repositories. Suppose a team is working on a project, then to collaborate on a git-enabled repository, they need to keep a copy of the project at a central place so that anyone can access it. Such a central platform is called the host and Github is a host. Hence, Git is a tool and Github is a service.

Why Use Github?

  • It acts as a central platform so that one can access the files easily

  • Github also act as a backup for our files, in case our machine gets destroyed.

    Branching & Merging

    Branching

    Branches are used to develop features isolated from each other. The default branch is the "master" branch whenever we create a repository. Other branches can be made whenever needed.

Merging

We use other branches for making any changes and add them back to master upon completion. The process of adding the new modified branch to the master branch is called merging.

Pulling & Pushing

Pulling

Pulling is the opposite of pushing. It allows you to make changes in your local repository from any remote location. it's more useful in group work or a big project where more than one person can submit changes to a single repository

Pushing

Pushing sends your changes up to GitHub, so they can be shared with your project teammates. It also serves as a hedge against data loss.

Basic Git Commands

  • git --version = To check whether git is installed, if installed then it tells its version
  • mkdir = To make a repository on local machine
  • touch = To add a file in the repository
  • git init = To initializing the Git repository
  • git add = To add particular file to the staging area
  • git add . = To add the whole folder to the staging area
  • git rm -cached = To remove file from the staging area
  • git commit -m "Message"= To add changes in the committed area with a message
  • git commit -am "Message" = To add files from the working tree to the committed area directly with a message
  • git status = To check the status of a repository
  • git log = To check the commit history
  • git checkout = To go back in a state of working tree in a particular commit
  • git restore --staged = To move a file from the staging area to the working area
  • git branch =To create a new branch
  • git checkout =To switches to an named branch
  • git merge =To merge the named branch in the current branch
  • git branch -d =To delete the named branch
  • git checkout -b = To create and switch to the named branch
  • git clone = To clone remote repository to local machine
  • git pull = To update your local repository to the newest commit
  • git push origin master = To move files to the master remote repository on the Github
  • git push origin =To move files to the branch remote repository on the Github
  • git checkout -b hotfix- = To create an temporary repository
  • git diff = To preview files before merging
  • gitk = Built-in git GUI
  • git config color.ui true = To use colourful git output
  • git config format.pretty oneline = Show log on just one line per commit
  • git add-i = Use interactive adding
  • git log --help = To get help
  • git log --name-status = To see only those files which have changed
  • git log --graph --oneline --decorate --all = If we wanna see an ASCII art tree of all the branches, decorated with the names of tags and branches