October 8, 2024 10:43 am
Topic starter
Notifications
Clear all
0
Agenda
---------------
- What is Git
- Types of Version Controlling
- What is git bash?
git terminal == git in windows
- Configure Git
- Types of files
- git init Observations
- How to move files to staging area
- How to know the status of the files
- How to move file to local repository
- How to see list of commits
-------------------------------------------------------------------------------------------------------
SCM (Source Code Management) Tools:
-----------------------------------
SCM tools help a software team to manage changes to source code over time.
code: is another name of a programm
source code: programm files whic was written to develop an application.
For almost all software projects, the source code is like the crown jewels - a precious asset whose value must be protected.
manage code ==> edit code, delete code, modify code & maintain code
source code management tools is also called as Version control systems
Need of Version Control System?
------------------------------------
Version control systems are a category of software tools that helps in recording changes made to files by keeping a track of modifications done in the code.
1) Maintaining multiple versions of code files manually is very complex activity.
2) Every change should be tracked like
- who did the change
- when he did the change
- which changes he did etc
and all changes should be maintained.
3) Overwriting of the code should not be happen.
4) Parallel development must be required
Two types VCS /SCM Tools:
-------------------------
1) Centrailized Version controlling
2) Distributed Version controlling
Centrailized Version controlling
-------------------------------
In a centralized sysytem all tem members connect to a central server to get the latest copy of the code and share their changes with others.
The problem with centralized archictecture is the single point failure if the server goes offline we can't collaborate or save coppy of our project, so we have to wait untill server come back online.
Distributed Version controlling
------------------------------
In distributed systems we don't have these problems, Every team member have a copy of the project with it's history on their machine(laptop), So we can save copy of our project locally on our machines (laptop).
SCM Tools:
-------------
- Git (Most advanced tool)
- SVN
- Perforce
- Clearcase
Git
----
Git is an open source distributed Version controlling tool
Git is most widely used VCS/SCM tool in the world.
Git originally developed in 2005 by Linus Torvalds, the famous creator of the Linux operating system kernel.
VCS records the chages made to our code overtime in a special database called Repository.
How to install git?
--------------------
Command to check if its installed perviously in server:
git --version
to install git:
yum install git ===> Redhat /amazon linux machines
apt install git ===> ubuntu machines
Install git in Windows?
-----------------------
gitbash ==> git for windows
to check where my file is currently?
------------------------------------
git status
to check commit history
git log
$ git init
git init == convert any directory ==> working directory (it will create .git directory)
Git Configuration:
------------------
Username & email configure needed for git ( only needed for first time)
$ git config --global user.name "ravi"
$ git config --global user.email "ravikumarg398@gmail.com"
TO check the configurations
$ git config --global --list
Git architecture
-----------------------
There are three main components in git architecture
1. Working directory ( Files will be called as ==> untracked files)
2. Staging area ( Files will be called as ==> staged file )
3. LocalRepository ( Files will be called as ==> commited file)
workflow of git:
-----------------
working directory ------> staging area -------> LocalRepository
(untracked files) (staged file) (commited file)
after running git init in any folder/directory, all files will be in that directory will be in untracked files state,
If we run git add command files will be moved to staging area, it‘s a intermediate area, where we can save the changes.
next we will run git commit, then files will get moved to Local repository then we can track the file/code version changes.
----------------------------------------------------------------------------------------------
How to make working directory as git repository
$ git init
git init command will convert any directory ==> git working directory
-Observation -
------------------------------------------------------------
$ git status
#to check where our files are currently in (working directory/staging area/LocalRepository)
------------------------------------------------------------
To move file from working directory to staging area:
$ git add <filename>
$ git add <filename2> <filename3>
$ git add .
Note: . (dot) ==> refers to all files in pwd
------------------------------------------------------------
To move the files from staging area to LocalRepository
$ git commit -m "<commit message>"
$ git status
------------------------------------------------------------
To see the list of commits history
$ git log
to see the commit history in single line format
$ git log --oneline
Note:
HEAD ==> points to latest commit
Branching
--------------
Branching is used for parallel development
two teams can work on same peice of code on two diffrent branches &
Later this code can be merged with master branch.
Default branch of git is "Master"
Developer
----------------
Home Page -- file1 file2 file3 ===> master branch
Services -- file4 file5 ==> <my_branch_2>
Contact US -- file6 file7 file8 ===> <my_branch_3>
personal banking - file10 file11 ==> new branch
+++++++++++++++++++++++++++++++++
# to create a branch
git branch <branchname >
# to list all branches
git branch
* ==> indicates your current branch
# to checkout to any branch
git checkout <branchname>
#to merge any branch
git merge <branchname>
note = be in your parent branch while merging
#to delete a branch
git branch -d <branchname>
++++++++++++++
Note
------
- as per git concept whenever you create a new branch, all previous commit history will also get copied on top of newly created branch
- merge event will also create commit automatically...
TAGS
-------
tag is a name given to version of files & directories
it indicates milestone in a project,
we can remember this very easily
#syntax
git tag <tagName>
#to check current tag / all tags
git tag
------------------------------------------------------------
Git Merge:
=============
Git merge is used to merge files of two different branches.
git merge <branchName>
GIT merge will arrange commits based on time
commit history after GIT MERGE: commit A , Commit B , commit C , COMMIT D , commit E , commit F
commit history after GIT ReBase: commit A , Commit B, commit F , commit C , COMMIT D , commit E
---------------------------------------------------------------
Git rebase
==============
rebase is nothing but a merge, but commit history will gets added on top of the branch.
Rebase is also called as fastforward merge.
The commits from the child branch are added to the top of the master branch.
with rebase we can modify the commit history.
Difference between git merge & git Rebase
=========================================
---------------------------------------------------------------------------------------------------------------------------------------|
Git Merge | Git Rebase
--------------------------------------------------------------------------------------------------------------------------------------- |
- commit history can not be modified in gitmerge | - commit history will get modified in git Rebase
- Commit history will be in linear format(based on time) | - Commit history will be in Non-linear format (based on branch)
|
- Merge doesnt provide clean project history | - rebase provides cleaner project history
|
- Merge is simpler activity | - Rebase is a little bit complex activity
|
----------------------------------------------------------------------------------------------------------------------------------------|
Note:
-----
Git rebase demo & commands
mkdir project1
cd project1/
git init
touch f1
git add f1
git commit -m "commit A"
touch f2
git add f2
git commit -m "commit B"
##creating a new branch
git branch test
## to checkout to new branch (i.e. test)
git checkout test
touch t1
git add .
git commit -m "commit C"
touch t2
git add .
git commit -m "commit D"
touch t3
git add .
git commit -m "commit E"
git log --oneline
#checking out to master again for new requirement in master branch
git checkout master
touch f3
git add .
git commit -m "commit F"
git log --oneline
######### Rebase ###########
git checkout <childBranch>
git rebase master
Note: rebase command should be executed on child branch only (i.e testbranch)
######## git merge to complete rebasing feature ###########
git checkout master
git merge test
===================================================================
Git stash:
---------
- Git stash command is used for leaving unfinished work.
- git stash temporarily saves the changes you've made to your files which are not commited, so you can work on some other branch, and then come back and re-apply them later on
- Stash works only on stagged files or non-commited files
usecase: if we have unfinished work / non commited files, then we cant switch to another branch in this we need to use git stashing
# To stash files
git stash
# To bring back the satshed changes
git stash pop
++++++++++++++++++++++
Git stash
=========
mkdir myproject1
cd myproject1
git init
touch f1 f2
git add .
git commit -m "commit A"
touch f3 f4
git add .
touch f5 f6
git status (2 staged files, 2 untracked file)
###stash
git stash
ls -lrth (see 4 files==> f1 f2 f5 & f6) f3 & f4 files are hidden
git add .
git commit -m "commit B"
git status
#####To bring back stashed files
git stash pop
Note:
------
INSTALL ==> installing is activity, which we are doing for very first time on fresh machine / server
UPDATE / UPGRADE ==> moving to next version of software
ROLLBACK ==> Going back to previous version of software
eg:
WhatsApp:
--------
version1 version2 version3 version4 version5 version6
Messaging =====> audioCalling feature =====> videocalling ======> Status ==========> UPI ====> XYZ