(Git Notes) - TheTestingAcademy (Pramod Sir)
(Git Notes) - TheTestingAcademy (Pramod Sir)
Source-https://sdet.live
y
Install Git into the System
What is GIT?
m
Why Use Git?
GIT vs Github vs Gitlab
Git Architecture
de
Configuring Git
.git Directory
Commands
ca Creating a new repository
Checking the status
Commiting
gA
Blame
Remote repositories
Connecting to a remote repository
tin
Cloning a repository
Getting changes from a server
Branches
es
y
How to save local changes made without committing or moving them to remote
repository?
✅
m
How to use stashed changes in git local repo so as to commit to remote repository?
Command Used: git stash apply
✅ GIT Workflow:
de
ca
Install Git into the System
1. L inux - Simply open up a new terminal and install Git via your distribution's package
gA
manager. For Ubuntu, the command is:sudo apt-getinstall git
2. Windows - we recommendgit for windowsas it offersboth a GUI client and a BASH
command line emulator.
3. OS X - The easiest way is to install Homebrew, and then just runbrew install git
tin
What is GIT?
eT
G
● it is a version control system that is used for tracking changes to files.
● It does this through a series ofsnapshots of yourproject.It works with those
snapshots to version and manage your source code, and it does this in a simple way.
Th
y
m
de
ca
Git Architecture
gA
tin
es
eT
de
git config --global user.name
$ "My Name"
$ git config --global user.email
[email protected]
ca
git config --global --list
.git Directory
gA
The .git directory contains all the configurations, logs, branches, HEAD, and more
Commands
tin
git init
eT
Staging
● Git has the concept of a "staging area".
● You can think of this like a blank canvas, which holds the changes which you would
like to commit.
● It starts out empty, but you can add files to it (or even single lines and parts of files)
with the git add command, and finally commit everything (create a snapshot) with git
commit
it add
g
git add hello.txt
git add . // Add everything
git status
ommiting
C
A commit represents the state of our repository at a given point in time.
It's like a snapshot, which we can go back to and see how thing were when we took it.
y
Blame
xamine specific parts of the code’s history and find out who was the last author to modify
E
m
that line “`bash.
Show what revision and author last modified each line of a file
https://git-scm.com/docs/git-blame
de
Remote repositories
ca
git remote add
gA
Connecting to a remote repository
1. In order to upload something to a remote repo.
2. Create a Repo at Github.com and Add Remote to it.
tin
3. The Git command to do this is git push and takes two parameters.
the name of the remote repo (we called ours origin) and the branch to push to
es
it
g add .
git
commit -m “blah blah”
Th
git
remote add origin https:
//github.com/PramodDutta/Restfulbooker.git
git
push origin main
Cloning a repository
● Download locally and have a fully working copy of your project
git clone https:
//github.com/PramodDutta/Restfulbooker.git
Branches
C
● opy of the original project, called a branch.
● Developers can work on their own branch, without the risk of their codebase
changing due to someone else's work.
● An already working, stable version of the code won't be broken.
y
●
m
de
ca
gA
tin
es
Switching branches
Th
Merging branches
TEMPORARY COMMITS
y
it stash
g
//Save modified and staged changes
m
git stash list
//list stack-order of stashed file changes
de
git stash pop
//write working from top of stash stack
git stash drop
ca
//discard the changes from top of stash stack
gA
Little Advanced
y
=======
// Use forEach to console.log contents.
m
arr.forEach(function(item) {
console.log(item);
});
de
>>>>>>> Tim
's commit.
Git Bisect
● G it bisect is a command in the Git version control system that helps in identifying the
tin
● ttps://education.github.com/git-cheat-sheet-education.pdf
h
● https://tutorialzine.com/2016/06/learn-git-in-30-minutes
● https://www.geeksforgeeks.org/git-difference-between-merging-and-rebasing/
Th
● https://learnxinyminutes.com/docs/git/
hat is GIT?
W
GIT is a version control and source code management (SCM) system that is designed to
handle both small and large projects quickly and efficiently.
What is GIT version control?
● GIT version control enables you to monitor the evolution of a group of files (code
files).
● It allows for the creation of several versions of a file collection. Each version saves a
snapshot of the files at a specific point in time, and the snapshot can be used to
revert the collection of files. (The code can be developed in different versions of
Java, and can be merged in Git)
● VCS permits switching between these versions. These versions are often maintained
in a location known as a repository. (You can move between Java versions during the
development process.)
y
m
hat is a Distributed Control System?
W
Later, the code is sent from our local workstation to the central repository (GitHub). Working
does not require a connection to a centralized repository.
de
ca
ow to configure GitHub repository locally?
H
gA
# git config --global alias.lo "log --oneline" -----> To create an Alias to Command
# git config --global --unset alias.lo -----> To Remove an Alias
# git config --global --unset user.name -----> to remove username
tin
To add files from work area to Index/staging/cache area. # git add
● it log -----> To show the Git Commits
g
● git log -5 -----> To show Recent 5 Commits
● git log --oneline -----> To Display the each commit in one line
● git log --since=2023-01-21
● git log --until=2023-01-01
● git log --author="user_name"
● it log --grep="Index"
g
● git log --oneline --author="user_name"
y
m
de
ca
gA
ow to edit an incorrect commit message in Git? Or How can you fix a broken
H
commit?
git commit --amend -m "This is your new Git Message"
tin
y
m
de
ca
hat is Git and how does it work?
W
Git is a version control system that tracks changes to files and directories. It allows multiple
gA
people to work on the same project simultaneously and keeps track of all changes made to
the files.
tin
command prompt. This will initialize a new repository in the current directory.
y
[branch name]" in the terminal or command prompt. This will send the changes made to the
repository to the remote repository.
m
ow do I create a new branch in Git?
H
To create a new branch in Git, you can use the command "git branch [branch name]" in the
de
terminal or command prompt. This will create a new branch in the repository that can be
used to make changes without affecting the master branch.
ca
ow do I switch between branches in Git?
H
gA
To switch between branches in Git, you can use the command "git checkout [branch name]"
in the terminal or command prompt. This will switch to the specified branch and make it the
active branch.
tin
command prompt. This will open a tool that allows you to compare and resolve conflicts
between different versions of a file.
Th
y
To create a tag in Git, you can use the command "git tag [tag name]" in the terminal or
command prompt. This will create a new tag that can be used to mark a specific commit in
m
the repository.
de
To push a tag to a remote repository, you can use the command "git push [remote name] [tag
name]" in the terminal or command prompt. This will send the specified tag to the remote
repository.
ca
ow do I view the status of a Git repository?
H
gA
To view the status of a Git repository, you can use the command "git status" in the terminal
or command prompt. This will show the current state of the repository, including changes
that have been made but not yet committed.
tin
To remove a remote repository in Git, you can use the command "git remote remove [remote
name]" in the terminal or command prompt. This will remove the specified repository as a
remote that can be accessed and pushed to.
ow do I configure Git?
H
To configure Git, you can use the command "git config" in the terminal or command prompt.
This allows you to set various settings for your Git installation, such as your name and email.
y
ow do I view the commit history in Git?
H
m
To view the commit history in Git, you can use the command "git log" in the terminal or
command prompt. This will display a list of all commits made to the repository, along with the
commit message, author, and date.
de
ow do I view the difference between two commits in Git?
H
To view the difference between two commits in Git, you can use the command "git diff
ca
[commit hash 1] [commit hash 2]" in the terminal or command prompt. This will display the
changes made between the two specified commits.
gA
ow do I cherry-pick a commit in Git?
H
To cherry-pick a commit in Git, you can use the command "git cherry-pick [commit hash]" in
the terminal or command prompt. This will apply the changes made in the specified commit
to the current branch.
tin
To merge a branch in Git, you can use the command "git merge [branch name]" in the
terminal or command prompt. This will combine the changes made on the specified branch
with the current branch.
Th
y
ow do I clone a repository in Git?
H
m
To clone a repository in Git, you can use the command "git clone [repository URL]" in the
terminal or command prompt. This will create a copy of the specified repository on your local
machine.
de
ca
IT Notes(with Interview QnA) - for
G
Automation Testers / SDET
gA
tin
Important GIT Command Useds which can be used day to day life for managing
code on remote repositories.
es
✅
To initialize a repository or create new git repository in your
local system -
eT
✅ What are the new changes and files updated in your code?
Command Used: git status
y
iii. Copy the http url, then use following
m
de
✅ Pushing the code to remote repository
Command Used: git push origin <branch_name>
ca
✅ How to review the current branch?
gA
Command Used: git branch (it reflects all existing branches and current working branch)
tin
Command Used: git remote set-url origin <url>
Th
y
Command Used: git reset
m
✅ How to create a git-ignore file?
de
ommand Used: touch .gitignore (works in git-bash)
C
Mac Terminal: git add .gitignore
ca
✅ How to get a new repository in your local system?
Command Used: git clone <remote_repo_url>
gA
Command Used: git pull origin master (branch_name)
✅
How to save local changes made without committing or moving
them to remote repository?
Command Used: git stash
ote: Used when you want to save local changes temporarily that are not yet committed. Its
N
primary use is when you want to switch a branch or work on different task.
✅
How to use stashed changes in git local repo so as to commit to
remote repository?
y
m
✅ GIT Workflow:
de
ca
gA
tin
es
eT
Th
Th
eT
es
tin
gA
ca
de
m
y