What is Git and how it works?

Git is a free and open-source Distributed Version Control System (DVCS), a tool to manage your source code within a development team.

It was developed by Linus Torvalds in 2005 who is also the creator of the Linux kernel. Git was his second big project which came into existence to manage his first big project i.e. Linux kernel. This helped to manage the Linux kernel code changes done by a team of thousands of people.

In a typical Centralized Version Control System (CVCS), the source code is maintained int the repository stored on a remote server. Git is termed as distributed because the source code repository is not only stored on the server but also stored on each development machine. The copy stored locally is called a local repository whereas the one stored on the server is called a server repository. Each developer can work on their local repository to commit (save) code changes locally. Once the changes are tested locally they can be merged into a server repository by performing a PUSH operation. Similarly, the latest code changes stored on the server can be fetched using a PULL operation.
What is Git and how it works
To use Git on the command-line you will have to download, install and configure Git on your computer however Git is available out-of-the-box in Mac machines. The Windows version of Git is called GitBash.

Git is the most popular version control system and almost all IDEs support Git out-of-the-box so we generally don’t require to execute the Git commands manually, but there are instances where we need to run Git commands from the terminal console.

You can also see the list of all Git commands by executing git help -a
You can also see the list of all Git concepts by executing git help -g

Most commonly used Git commands are listed below:

usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]

Common Git commands are grouped together to use in different scenarios:

To start a working area:

   clone     Clone a repository into a new directory
   init      Create an empty Git repository or re-initialize an existing one

To work on the current change:

   add       Add file contents to the index
   mv        Move or rename a file, a directory, or a symlink
   reset     Reset current HEAD to the specified state
   rm        Remove files from the working tree and from the index

To examine the history and state:

   bisect    Use binary search to find the commit that introduced a bug
   grep      Print lines matching a pattern
   log       Show commit logs
   show      Show various types of objects
   status    Show the working tree status

To grow, mark and tweak your common history:

   branch    List, create or delete branches
   checkout  Switch branches or restore working tree files
   commit    Record changes to the repository
   diff      Show changes between commits, commit and working tree, etc
   merge     Join two or more development histories together
   rebase    Reapply commits on top of another base tip
   tag       Create, list, delete or verify a tag object signed with GPG

To collaborate:

   fetch     Download objects and refs from another repository
   pull      Fetch from and integrate with another repository or a local branch
   push      Update remote refs along with associated objects

See 'git help <command>' or 'git help <concept>' to read about a specific command or concept.

More on Git can be learnt from this article.

No comments:

Post a Comment