Git

What is Git?

Git is a distributed version control system (VCS) for tracking changes in computer files and coordinating work on those files among multiple people.
Version control system is a system that records changes to a file or set of files over time so that you can recall specific versions later. Unlike a central VCS, a distributed VCS has both remote and local repositories. As a result, it does not require the backup.

Installation and Setup

  1. Download Git from https://git-scm.com
  2. Enter Configuration Values:
    $ git config --global user.name "firstName lastName" - your name
    $ git config --global user.email "example@gmail.com" - your email
  3. Check Your Settings:
    $ git config --list

help

To open a manual and display information about Git:
$ git help -a or $ git help --all - shows a list of all available commands
$ git help config - explains how to use the Git verb, in this case, config
$ git help -g or $ git help --guide - shows a list of Git guides

New Repository

To create a New Repository:
$ git init
To clone a Remote Repository:
$ git clone /Url/

Staging Area

To add / propose changes:
$ git add /file/
To add everything:
$ git add .
To remove:
$ git reset /file/

commit

To commit changes:
$ git diff - shows the changes made
$ git commit -m "Detailed message explaining the nature of changes"
To push changes to remote repository:
$ git pull origin master
$ git push origin master

Workflow

Git project consists of three main sections:

  1. Working Directory
  2. Staging Area / Index
  3. HEAD

Three main states of files:

  1. Committed
  2. Modified
  3. Staged

Branches

A Git branch is a movable pointer to the commits. The default branch is called master.

To create a new branch: $ git checkout -b newBranch
To remove a branch: $ git branch -d newBranch
To go back to master: $ git checkout master
To push to the remote repository: $ git push origin /branch/
To merge a branch to current branch: $ git merge /branch/

log

To see the commit that was just made:
$ git log
The message, author, email, and other additional information will be displayed.

Git Checkout

$ git checkout -- /file/
or
$ git fetch origin - to cancel all the commits implemented locally

Resources

Git Community Book