Comprehensive Guide to Git and Its File Workflow
Version Control System
Is used to Version Control the Source Code Changes
Is used to Track the Source Code Changes
Type of VCS:
Local Version Control System (LVCS): Stores source files on a local system
Centralized Version Control System (CVCS): Stores changes in a single server
Distributed Version Control System (DVCS): Involves cloning a Git repository
The choice of VCS depends on the development team's needs and development process. Each type has its own advantages and disadvantages:
Local VCS: If your hard disk gets corrupted or you lose the file, you lose everything related to it.
Centralized VCS: If you lose the repo, everything is gone.
Distributed VCS: Even if someone's local repo is corrupted or the remote doesn't work, there is a copy available with other developers.
GIT
Is an Open-Source Distributed Version Control System
It is used to Version Control the Source Code Changes
Used to Track the Changes
Used to Perform Parallel Development using Branching Techniques
Remote GIT Repository Servers :
GitHub
Gitlab
Bamboo
Azure Repo
AWS Code Commit
Bitbucket
Working with GIT
Git Client - To be installed in the local machine
GitHub - Should have access to Remote github server
Git File Workflow
Git Branching Strategies
Handling Remote Git Repository(Github)
Git File Workflow
In Distributed VCS:
In Local Machine
Working Directory
- Is the physical memory location of the file.
Staging Area
Logical location used by to git to stage the changes.
Staging area acts as a interface between working directory and local repository.
Local Repository
- Logical location used by git to create permanent commit point.
Git CLI Commands
git clone - Used to clone/copy the entire remote repository to Local Machine(Working Directory and local Repo)
git add - Used to add the changes from working directory to staging area.
git commit - Used to permanently commit the changes from staging area to local Repository.
git push - Used to push the changes from local repo to Remote repo.
git pull / git fetch - Both git pull and git fetch are used to handle the incremental changes from Remote Repository.
git fetch
git fetch will just check for the incremental changes in the remote repository. If their is any incremental changes exist, it will update the details only in the local repository. git fetch will NEVER Update the Working Directory.
Upon git fetch, to work on the changes, we can use git pull or git merge
Using git merge the changes can be updated in the working directory
git pull
- git pull will check for the incremental changes in the remote repository. If their is any incremental changes exist, it will update the details in the local repository as well in the Working Directory.
git cherry-pick <commit_id>
It is used to merge specific commit to the target branch.
git cherry-pick is not recommended to use without proper branching strategy
Working with GIT Local Repositories using git cli commands
Open git bash/Terminal
Create the Directory
cd b:
mkdir git-projects
cd git-projects
mkdir repo1
cd repo1
git init
Is used to initialize the local git repository
Create a .GIT! Directory
Create a default branch called master/main
git config
To assign the default Author Name and Email ID
git config should be executed to set the user name and Email ID before the very initial commit.
GIT Local Configuration - It is applicable to a specific repository
git config user.name "gituser"
git config user.email "gituser@traning.com"
git config —list - to see the local configuration
GIT Global Configuration - It is applicable to all the repositories
git config --global user.name "gituser"
git config —global user.email “gituser@training.com”
git status - Used to get the status of git repository
Let’s commit a file from working directory to local repository
echo “commit test” >> test.txt
git add test.txt
git commit -m “first commit”
git status
git log
git add
git add <file_name>
git add *.txt
git add fi1e1.txt file2.txt file3.txt
git add .
-
ls - Linux Bash Command to get the list of files and folder from Working Directory
git ls-files - Is git command to get the list of files and folders that being tracked by git.
-
Unstaging - Remove the changes from staging area.
git rm --cached <file_name>
Used to Remove the Changes from Staging Area.
But, the Changes will be take back to working Directory.
The Changes that are remove, will be considered as Untracked Changes.
git rm -rf <file_name>
Used to Permanently remove the Changes from Staging Area as well as from the working directory.
git log
git log
git log - -oneline
git log -2
git log - -oneline -3
git log -stat
git log - -oneline - -all - -graph - -decorate
git show <commit_id>
git commit - Used to Create a permanent commit point
git commit -m "<commit Message>"
git commit --amend -m "Valid Message"
Used to Update the Commit Message of latest commit, Without creating New Commit Point.
git diff
Used to compare the changes between the working directory and Local Repository
To Compare the Changes between Commited and Uncommited Changes.