Table of Contents
ToggleGit is a distributed version control system (DVCS) that is
widely used for tracking changes in source code during software
development. Git was initially designed and developed by Linus
Torvalds for Linux kernel development. It is a free software
distributed under the terms of the GNU General Public License
version 2.
Git is distributed version-control system while GitHub is a
repository hosting service.
It is a great tool to track changes in files in any folder
which is called git repository. It has its own file structure.
Every file is stored in the separate document and has unique
hash value which is very useful to work with. It is simply
persistent hash map that stores key-value pairs. Key is the
hash and value is the content of file. Git doesn’t depend on
internet and stores everything locally.
GitHub manages your Git repository. It is basically used when
different users work on same project. You can also use it for
backup your repository.
Git has some key concepts which is widely useful in daily
development of products. It has version control, distribution,
branching, etc. You can commit your changes with comments and
which can be retrieved later when needed even you can restore
to it as well. It has push and pull feature so that you can
pull and push your data to remote repository.
Note: Git stores four types o objects blobs, trees, commits,
and tags.
On Windows:
Open this URL "https://git-scm.com/downloads" and go to windows
section, download it.
Click on installation and file follow some default and below
selection process.
* Use Visual Studio as editor. (Install Visual Studio)
* Git from the command line and also from 3rd part software.
* Use OpenSSL library.
* Checkout windows-style, commit Unix-style line endings.
* Use MinTTY (the default terminal of MSYS2).
It is installed, now open Gitbash and try some unix commands
like creating directory or files. You can check by initializing
the newly created directory.
w10@DESKTOP ~
$ cd Desktop/
w10@DESKTOP ~/Desktop
$ mkdir my-project
w10@D ~/Desktop
$ cd my-project/
w10@ ~/Desktop/my-project
$ touch file1.txt
w10@ ~/Desktop/my-project
$ touch file2.txt
w10@ ~/Desktop/my-project
$ ll
total 0
-rw-r--r-- 1 w10 197121 0 Nov 27 18:57 file1.txt
-rw-r--r-- 1 w10 197121 0 Nov 27 18:57 file2.txt
w10@ ~/Desktop/my-project
$
w10@ ~/Desktop/my-project
$ git init
Initialized empty Git repository in C:/Users/w10/Desktop/my-project/.git/
On Linux:
# yum install git
Initialize new Git repository:
To initialize new git repository where you want either any
folder, sub-folder. You need to run below command to initialize
the git repository.
# git init
Git repository will be initially empty even if directory where
you initialize Git is not empty and contains some files and
other directories.
# git init (Initialize a new Git repository)
# git clone <repository_url> (Clone a repository from remote URL)
# git add <file(s)> (Add changes to staging area)
# git commit -m "Commit message" (Commit changes)
# git status (Check status of your git repo)
# git branch <branch_name> (Create a new branch)
# git checkout <branch_name> (Switch to different branch)
# git checkout -b <branch_name> (Will create and switch to branhc after creating)
# git merge <source_branch> (Merge two branches)
# git branch -d <branch_name> (Delete Branhc)
# git remote add <remote_name> <remote_url> (Add a remote repository)
# git remote -v (List remote repository)
# git fetch <remote_name> (Fetch information from remote repository)
# git pull <remote_name> <branch_name> (pull information from remote repository to current branch)
# git push <remote_name> <branch_name> (Push changes to remote repository)
# git checkout -- <file(s)> (Discard changes)
# git reset <file(s)> (Unstage changes but keep them in your working directory)
# git revert <commit_hash> (Revert a commit)
# git reset --hard <commit_hash> (Reset to a previous commit)
# git log (Show commit histiry)
# git log --oneline (Show logs with more details like commit comments)
# git log --graph --oneline --all (Show a graphical representation)
One thought on “Git”