0% found this document useful (0 votes)
30 views

(Git Notes) - TheTestingAcademy (Pramod Sir)

Uploaded by

Adarsh Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

(Git Notes) - TheTestingAcademy (Pramod Sir)

Uploaded by

Adarsh Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

‭Learn GIT Basics‬‭)‬

‭Git Notes - TheTestingAcademy (Pramod Sir)‬

‭Source‬‭-‬‭https://sdet.live‬

‭Git Notes - TheTestingAcademy (Pramod Sir)‬

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

‭Creating new branches‬


‭Switching branches‬
‭Merging branches‬
eT

‭Merge and Rebase‬


‭TEMPORARY COMMITS‬
‭Little Advanced‬
‭Th

‭Reference and Download PDF‬


‭50+ Git Interview QnA:‬
✅ ‭ To initialize a repository or create new git repository in your local system -‬
✅ ‭ What are the new changes and files updated in your code?‬
✅ ‭ How to add files to the staging area?‬
✅ ‭ How to commit code to local git repo? (local repository not yet pushed to remote)‬
✅ ‭ How to push code to a remote repository?‬
✅ ‭ Pushing the code to remote repository‬
✅ ‭ How to review the current branch?‬
✅ ‭ How to create and update a working branch?‬
✅ ‭ How to update remote repository URL?‬

‭ How to get status and updates made in remote branches?‬

‭ How to update the local repository?‬

‭ How to delete a branch on local (after commit)?‬

‭ How to force delete a branch?‬

‭ How to remove files from the staging area?‬

‭ How to create a git-ignore file?‬

‭ How to get a new repository in your local system?‬

‭ How to search for text in the current working repo/directory?‬

‭ How to create and move branch working directory (local)?‬

‭ How to fetch the latest changes from remote to local?‬

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-get‬‭install git‬
‭2.‬ ‭Windows - we recommend‬‭git for windows‬‭as it offers‬‭both a GUI client and a BASH‬
‭command line emulator.‬
‭3.‬ ‭OS X - The easiest way is to install Homebrew, and then just run‬‭brew install git‬
tin

‭from your terminal.‬


es

‭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 of‬‭snapshots of your‬‭project.‬‭It works with those‬
‭snapshots to version and manage your source code, and it does this in a simple way.‬
‭Th

‭Why Use Git?‬


‭‬
● ‭ an work offline.‬
C
‭●‬ ‭Collaborating with others is easy!‬
‭●‬ ‭Branching is easy!‬
‭●‬ ‭Branching is fast!‬
‭●‬ ‭Merging is easy!‬
‭●‬ ‭Git is fast.‬
‭●‬ ‭Git is flexible.‬
‭GIT vs Github vs Gitlab‬
‭●‬ G ‭ it is a version control system, while GitHub and GitLab are web-based Git‬
‭repositories.‬
‭●‬ ‭GitHub is a company that provides Git hosting, and it offers both a cloud-based‬
‭hosting service and on-premises enterprise versions.‬
‭●‬ ‭GitLab is similar to GitHub, but it is an open-source Git hosting platform. It provides a‬
‭web-based interface for working with Git repositories, as well as a range of tools for‬
‭collaboration, project management, and continuous integration.‬
‭Git is a version control system‬‭, GitHub is a Git hosting‬‭service, and GitLab is an open-source‬
‭Git hosting platform.‬

y‬
m
de
ca
‭Git Architecture‬
gA
tin
es
eT

‭With Remote Repo‬


‭Th
y‬
m
‭Configuring Git‬

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

‭Creating a new repository‬


es

git init‬

eT

‭Checking the status‬


git status‬

‭Th

‭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.‬

git commit -m‬‭


‭ "Initial commit."‬

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

git remote add origin https:‬


‭ //github.com/PramodDutta/Restfulbooker.git‬

‭Add File and Push‬


eT

‭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‬

‭ etting changes from a server‬


G
‭If you make updates to your repository, people can download your changes with a single‬
‭command‬
git pull origin master‬

‭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

‭Creating new branches‬


eT

git branch new_feature‬


‭Switching branches‬
‭Th

git checkout new_feature‬


‭Merging branches‬

‭it add feature.txt‬


g
git commit -m "New feature added"‬

git checkout main‬

git merge‬

// Remove old branch‬

git branch -d amazing_new_feature‬

‭Merge and Rebase‬


‭https://www.geeksforgeeks.org/git-difference-between-merging-and-rebasing/‬

‭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‬

‭1.‬ ‭Setting up .gitignore‬


tin

‭a.‬ ‭log files‬


‭b.‬ ‭task runner builds‬
‭c.‬ ‭the node_modules folder in node.js projects‬
es

‭d.‬ ‭folders created by IDEs like Netbeans and IntelliJ‬


‭e.‬ ‭personal developer notes‬
eT

‭2.‬ ‭Check the diff between commits, use the‬


git log‬

‭3.‬ ‭Want to see in that commit, diff?‬
‭Th

git show <commit Id>‬



‭4.‬ ‭Want to see diff from 1 to 2 ids‬
git diff‬‭
‭ 09‬
bd8cc..ba25c0ff‬

‭5.‬ ‭Reverting a file to a previous version.‬
git checkout‬‭
‭ 09‬
bd8cc1 hello.txt‬

‭6.‬ ‭Fixing a commit and Revert to Head‬
‭a.‬ ‭newest commit can be accessed by the HEAD alias.‬
git revert HEAD‬

git revert b10cc123 // Or‬

‭7.‬ ‭Resolve conflict‬


‭a.‬ ‭git merge tim_branch‬
‭<<<<<< HEAD‬
<
// Use a for loop to console.log contents.‬

for‬
‭ (var i=‬
‭ 0‭
‭;
‬ i<arr.length; i++) {‬
console.log(arr[i]);‬

}‬

y‬
=======‬

// Use forEach to console.log contents.‬

m
arr.forEach(function(item) {‬

console.log(item);‬

});‬

de
>>>>>>> Tim‬
‭ 's commit.‬

‭ git add -A‬


$
ca
$ git commit -m "Array printing conflict resolved."‬

gA

‭Git Bisect‬

‭●‬ G ‭ it bisect is a command in the Git version control system that helps in identifying the‬
tin

‭commit that introduced a bug or change in the code‬


‭●‬ ‭It works by performing a binary search through the commit history to find the commit‬
‭that caused the change.‬
es
eT
‭Th
y‬
m
de
ca
‭Here is an example of how you can use Git bisect in the command line:‬
gA
‭Start the bisect process:‬

‭ git bisect start‬


$
‭#Mark the current state of the code as "bad":‬
tin

‭ git bisect bad‬


$
‭# Mark the known good state of the code:‬
es

‭ git bisect good <commit-hash>‬


$
‭Git will then checkout a commit in the middle of the good and bad commits. You can test the‬
‭code to see if it is working as expected. If it is, you can mark it as "good":‬
eT

‭ git bisect good‬


$
‭If the code is not working, you can mark it as "bad":‬
‭Th

‭ git bisect bad‬


$
‭Git will then checkout another commit and you can repeat steps 4 and 5 until Git bisect has‬
‭found the specific commit that caused the issue.‬

‭Finally, end the bisect process:‬

‭ git bisect reset‬


$
‭This is a simple example of how you can use Git bisect to find the specific commit that‬
‭caused a change or bug in your code. Bisect is a powerful tool that can save you a lot of‬
‭time and effort in debugging and fixing issues in your code.‬
y‬
m
de
ca
gA
tin
es

‭Reference and Download PDF‬


eT

‭‬
● ‭ 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/‬

‭50+ Git Interview QnA‬‭:‬

‭ 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

‭ hat is the git clone?‬


W
‭To download an existing repository from Centralized (Github) to local system. # git clone‬
es
eT

‭ hat is ‘git add’?‬


W
‭Th

‭To add files from work area to Index/staging/cache area. # git add‬

‭ hat is the use of ‘git log’?‬


W
‭To see the commits by content or history, author‬

‭‬
● ‭ 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

‭ ow do you undo the last commit?‬


H
‭git revert <your commit id>‬
es

‭ hat is git reset?‬


W
‭Reset the current HEAD state to specific state.‬
eT

‭ ow to delete a Remote Branch?‬


H
‭git push origin -d‬
‭Th

‭How to see the difference between 2 branches‬

‭git diff <name of branch 1>..<name of branch 2>‬

‭ hy GIT better than Subversion (SVN)?‬


W
‭Git is an open-source version control system that allows you to perform a project's'version'‬
‭command.‬
‭Each modification can be linked to a specific developer. Multiple developers can check out‬
‭and post changes.‬
‭ hat is git stash?‬
W
‭Stashing takes the Temporary stored state of your working directory.‬

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

‭ hat is a Git repository?‬


W
‭A Git repository is a collection of files and directories that are tracked by Git. It is a place‬
‭where all the changes to a project are stored and can be accessed by other users.‬
es

‭ hat is a commit in Git?‬


W
‭A commit in Git is a snapshot of the current state of a project. It is a way of saving changes‬
‭made to the files and directories in a Git repository.‬
eT

‭ ow do I create a new Git repository?‬


H
‭To create a new Git repository, you can use the command "git init" in the terminal or‬
‭Th

‭command prompt. This will initialize a new repository in the current directory.‬

‭ ow do I clone a Git repository?‬


H
‭To clone a Git repository, you can use the command "git clone [repository URL]" in the‬
‭terminal or command prompt. This will create a copy of the repository on your local machine.‬

‭ hat is the difference between git pull and git fetch?‬


W
‭git pull is used to fetch changes from a remote repository and merge them into the current‬
‭branch. git fetch is used to fetch changes from a remote repository, but it does not merge‬
‭them into the current branch.‬

‭How do I add a file to a Git repository?‬


‭ o add a file to a Git repository, you can use the command "git add [file name]" in the‬
T
‭terminal or command prompt. This will add the file to the repository and prepare it for a‬
‭commit.‬

‭ ow do I commit changes in Git?‬


H
‭To commit changes in Git, you can use the command "git commit -m [commit message]" in‬
‭the terminal or command prompt. This will save the changes made to the files and‬
‭directories in the repository.‬

‭ ow do I push changes to a remote repository?‬


H
‭To push changes to a remote repository, you can use the command "git push [remote name]‬

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

‭ ow do I merge branches in Git?‬


H
‭To merge branches in Git, you can use the command "git merge [branch name]" in the‬
‭terminal or command prompt. This will combine the changes made to the specified branch‬
‭with the current branch.‬
es

‭ ow do I resolve conflicts in Git?‬


H
‭To resolve conflicts in Git, you can use the command "git mergetool" in the terminal or‬
eT

‭command prompt. This will open a tool that allows you to compare and resolve conflicts‬
‭between different versions of a file.‬
‭Th

‭ ow do I view the history of a Git repository?‬


H
‭To view the history of a Git repository, you can use the command "git log" in the terminal or‬
‭command prompt. This will show a list of all the commits made to the repository.‬

‭ ow do I revert a commit in Git?‬


H
‭To revert a commit in Git, you can use the command "git revert [commit hash]" in the‬
‭terminal or command prompt. This will undo the changes made in the specified commit and‬
‭create a new commit to reflect the changes.‬

‭ ow do I delete a branch in Git?‬


H
‭To delete a branch in Git, you can use the command "git branch -d [branch name]" in the‬
‭terminal or command prompt. This will delete the specified branch from the repository.‬
‭ ow do I stash changes in Git?‬
H
‭To stash changes in Git, you can use the command "git stash" in the terminal or command‬
‭prompt. This will temporarily save changes made to the files and directories without‬
‭committing them.‬

‭ ow do I apply stashed changes in Git?‬


H
‭To apply stashed changes in Git, you can use the command "git stash apply" in the terminal‬
‭or command prompt. This will apply the changes that were previously stashed.‬

‭ ow do I create a tag in Git?‬


H

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.‬

‭ ow do I push a tag to a remote repository?‬


H

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

‭ ow do I create a remote repository in Git?‬


H
‭To create a remote repository in Git, you can use a service like GitHub or GitLab. This will‬
‭create a new repository on the remote server that can be accessed by other users.‬
es

‭ ow do I add a remote repository in Git?‬


H
‭To add a remote repository in Git, you can use the command "git remote add [remote name]‬
‭[repository URL]" in the terminal or command prompt. This will add the specified repository‬
eT

‭as a remote that can be accessed and pushed to.‬

‭ ow do I remove a remote repository in Git?‬


H
‭Th

‭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.‬

‭ ow do I check out a specific commit in Git?‬


H
‭To check out a specific commit in Git, you can use the command "git checkout [commit‬
‭hash]" in the terminal or command prompt. This will change the current branch to reflect the‬
‭state of the repository at the time of the specified commit.‬
‭ ow do I create a patch file in Git?‬
H
‭To create a patch file in Git, you can use the command "git format-patch [commit hash]" in‬
‭the terminal or command prompt. This will create a file that contains the changes made in‬
‭the specified commit.‬

‭ ow do I resolve a merge conflict in Git?‬


H
‭To resolve a merge conflict in Git, you can use a text editor to manually edit the conflicting‬
‭files and resolve any issues. Once the conflicts have been resolved, you can use the‬
‭command "git add" to stage the changes, and "git commit" to finalize the merge.‬

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

‭ ow do I rebase a branch in Git?‬


H
‭To rebase a branch in Git, you can use the command "git rebase [branch name]" in the‬
‭terminal or command prompt. This will reapply the commits made on the current branch onto‬
es

‭the specified branch.‬

‭ ow do I merge a branch in Git?‬


H
eT

‭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

‭ ow do I squash commits in Git?‬


H
‭To squash commits in Git, you can use the command "git rebase -i [commit hash]" in the‬
‭terminal or command prompt. This will open an editor where you can specify which commits‬
‭to squash together.‬

‭ ow do I rename a branch in Git?‬


H
‭To rename a branch in Git, you can use the command "git branch -m [old branch name] [new‬
‭branch name]" in the terminal or command prompt. This will change the name of the‬
‭specified branch.‬

‭How do I view the branches in a Git repository?‬


‭ o view the branches in a Git repository, you can use the command "git branch" in the‬
T
‭terminal or command prompt. This will display a list of all branches in the repository.‬

‭ ow do I view the remote branches in a Git repository?‬


H
‭To view the remote branches in a Git repository, you can use the command "git branch -r" in‬
‭the terminal or command prompt. This will display a list of all remote branches in the‬
‭repository.‬

‭ ow do I view the current branch in Git?‬


H
‭To view the current branch in Git, you can use the command "git branch" in the terminal or‬
‭command prompt. The current branch will be indicated with an asterisk (*) next to its name.‬

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

I‭mportant 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

‭Command Used: git init‬


‭Th

✅ What are the new changes and files updated in your code?‬

‭Command Used: git status‬

✅ How to add files to the staging area?‬



‭Command Used: git add * / git add <filename>‬

‭ How to commit code to local git repo? (local repository not yet‬
‭pushed to remote)‬
‭Command Used: git commit -m “<message>”‬

✅ How to push code to a remote repository?‬



‭ ns:‬
A
‭i. Authenticate yourself by using token or basic authentication‬
‭ii. Create a repository on your github account‬

y‬
‭iii. Copy the http url, then use following‬

‭Command Used: git remote add origin <remote_url>‬

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

✅ How to create and update a working branch?‬



es

‭Command Used: git branch -M <branch_name>‬

✅ How to update remote repository URL?‬


eT


‭Command Used: git remote set-url origin <url>‬
‭Th

✅ How to get status and updates made in remote branches?‬



‭Command Used: git diff origin/<branch_name>‬

✅ How to update the local repository?‬



‭Command Used: git pull origin <branch_name>‬
✅ How to delete a branch on local (after commit)?‬

‭Command Used: git branch -d <branch_name>‬

✅ How to force delete a branch?‬



‭Command Used: git branch -D <branch_name>‬

✅ How to remove files from the staging area?‬


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

✅ How to search for text in the current working repo/directory?‬



tin

‭Command Used: git grep <text>‬


es

✅ How to create and move branch working directory (local)?‬



eT

‭Command Used: git checkout -b <branch_name>‬

✅ How to fetch the latest changes from remote to local?‬


‭Th


‭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?‬

‭Command Used: git stash apply‬


‭ ote: Use the changes which were stashed earlier. Please check before applying the‬
N
‭changes you switch to the repository for which changes were made.‬

y‬
m
✅ GIT Workflow:‬

de
ca
gA
tin
es
eT
‭Th
‭Th
eT
es
tin
gA
ca
de
m
y‬

You might also like