GIT Notes
GIT Notes
==============================================================================
What is Version control system ?
==============================================================================
Version control system provides an unique version for tracking and optimizing the
storage cost via SHA 125/256 with help of commit id's.
==============================================================================
Why Version Control system ?
==============================================================================
1. Tracking : username - name
email - email-id
2. Storage cost:
DAY 1 : login.java -> 1 GB data -> execution & testing -> stable/working file
Record the changes via commit id -> dnon93b9f2bibnad02nr20osdf
commit-id -> unique random id -> SHA-125/256 (secure hashing alogirthm) -
16 digit octect - alpha-numberic
DAY 2: login.java -> 4 GB data -> execution & testing -> stable/working file
Record the changes via commit id -> mxjdhdjh983bfb9bb9bbfd
commit-id -> unique random id -> SHA-125/256 (secure hashing alogirthm) -
16 digit octect - alpha-numberic
DAY 3 :login.java -> 10 GB data -> execution & testing -> stable/working file
Record the changes via commit id -> lsdmdjho0h0h9ddud00d
commit-id -> unique random id -> SHA-125/256 (secure hashing alogirthm) -
16 digit octect - alpha-numberic
=============================================
Traditional way of storing the code:
=============================================
Windows/Linux :
2. Storage cost :
DAY 1 : login.java -> 1 GB data -> execution & testing -> stable file -> 10 lines
- Day -2 - 3 lines
backup_login.java_27062023 - 1 GB data
DAY-2 : login.java -> 1 GB + 3 GB = 4 GB -> execution & testing -> stable file -
20 lines
backup_login.java_28062023 - 4 GB data
DAY -3: login.java -> 4 GB + 10 GB -> -> execution & testing -> stable file
===================================================================================
=====================
Types of Version control system(VCS):
===================================================================================
=====================
1. Centrailized VCS - clearcase, SVN
2. Distributed VCS - Git/Github , bitbucket
===================================================================================
================================
Architecture of GIT :
===================================================================================
================================
GIT - CLI
GITHUB - GUI
Working directory
Staging Area
Local Repo
Remote Repo
===================================================================================
================================
Installation of Git :
===================================================================================
=============================
Method 1 : Package Manager
===================================================================================
==============================
Basic commands:
===================================================================================
==============================
1. How to check git version
command: git --version
===================================================================================
============================
2. How to create a repository in git ?
command: git init Repository_name
(OR)
mkdir - /opt/project
cd project
git init
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
file.txt
nothing added to commit but untracked files present (use "git add" to track)
[root@ip-172-31-17-229 git-operations]#
===================================================================================
===========================
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: file.txt
[root@ip-172-31-17-229 git-operations]#
===================================================================================
===========================
5. How to check where is my file located currently?
===================================================================================
===========================
6. How to record the file changes?
===================================================================================
===========================
7. How to check the commits created ?
command: git log // list all the commits with detailed info
git log -n1 // last commit
git log -n2 // last 2 commits
git log --oneline // short commit and messages
===================================================================================
==============================
8. How to check detailed information on the commit ?
===================================================================================
================================
Note :
(use "git rm --cached <file>..." to unstage
===================================================================================
================================
Branches :
===================================================================================
==============================
Branches are nothing but logical folders/directories who stores all the
files,directories and unqiue commits.
Branch segregates the work keeping the files/directories and commits uniquely.
With branches, we can re-use the code for other applications.4
Branches are very cheap thats means we can create and delete a branch easly and
branches doesnt occupy more spaces.
eg : TREE(GIT)
|
BRANCH(short) BRANCH(tall)
BRANCH(big)
|
Sub branch(folders) flowers(files) fruits(commits) flowers fruits
Sub branch fruits
eg : Ecommerce website
* login page
* logout oage
* product catalog
* payment pages
* add to cart
Single Branch :
Developer -> Branch(master) -> login.java - 1000 lines -> 15 commits
logout.java - 500 lines -> 10 commits
product catalog - 2000 lines - 30 commits
payment pages - 1000 lines -> 20 commits
add to cart - 200 lines - 10 commit
Feature wise branches : login-feature branch -> login.java - 1000 lines -> 15
commits
login-security.java
Final Branch - ecommerce-website branch or (master) -> combine all the above
branches into single -> build and generate aritfact.
===================================================================================
=
Standard Branches :
===================================================================================
=
1. master/main branch : Contains always latest and updated code/scripts
2. develop branch : Development and testing code/script
3. release branch : Ready to move for production/live
- flipkart-release-1.0
- flipkart-release-2.0
4. feature branch: Feature releated branches
* login-page feature branch
* payment-page branch
5. Hotfix branch : Live issues or customer tickets are managed here
* logout-issues-ticket-number
eg : master M1 M2 M3 M4
master > git merge develop
develop M1 M2 M3 M4 M5
develop M1 M2 M3 M4 M5 M6
master M1 M2 M3 M4 M5 M6 M7 MC
develop M1 M2 M3 M4 M5
M6=================================================================================
==================================
Rebase : Rebase is used for re-writing the history on top of base branch. Rebase
will keep the history clean without combining any commits together.
eg : develop M1 M2 M3 M4 M5 M6 M7 M8
release M1 M2 M3 M4 M5
eg : develop M1 M2 M3 M4 M5 M6 M7 M8
release M1 M2 M3 M4 M5 M6 M8
===================================================================================
=========================================
Revert : Revert is mechanism used to undo/rollback the changes and revert will
create new commit for every rollback/undo operation perform.
eg : master M1 M2 M3 M4 M5 M8
develop M1 M2 M3 M4 M5 M6 M7 M8
===================================================================================
=====================================
Github Account Creation:
===================================================================================
==================================
Github Administration : PART-1
===================================================================================
==============================
1. How to create repository?
===================================================================================
=======
Types of clones :
===================================================================================
=======
1. HTTPS : URL - https://github.com/GoudSagar/training-devops-work.git
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
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 ---shyam
===================================================================================
===
2. SSH : URL - [email protected]:GoudSagar/training-devops-work.git
b. go to profile -> settings -> SSH & GPG Keys -> add new ssh key
===================================================================================
=====================
Ticket : project.txt -> 10 lines
commit your changes in local repo
vi project.txt
git status
git add .
git status
git commit -m "Ticket - messages"
===================================================================================
=====================
git push : Push is mechanism for uploaded the changes(commits/files/directories)
from local repo to remote repository.
===================================================================================
===================================
git pull : Pull is mechanism used for downloading the updated changes from remote
repository to local repository.
command: git pull origin main
============================================================================
git pull = git fetch + git merge
Alais -> Short name for github url's for easily identifying the repo url and easily
pushing & pulling changes to & from
remote repos.
git remote -v
origin [email protected]:bathinisreelatha/Ansible-repo.git(push)
origin [email protected]:bathinisreelatha/Ansible-repo.git(fetch)
upstream [email protected]:goudsagar/Ansible-repo.git(push)
upstream [email protected]:goudsagar/Ansible-repo.git(fetch)