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

Git Notes

This document provides instructions for using common Git commands. It explains how to initialize a Git repository, add and commit files, view commit history and status, manage branches, and connect a local repository to a remote repository on GitHub. Key points covered include initializing and cloning repositories, tracking and committing file changes, creating and deleting branches, and pushing commits to a remote origin like GitHub.

Uploaded by

Ajay Babu M
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
168 views

Git Notes

This document provides instructions for using common Git commands. It explains how to initialize a Git repository, add and commit files, view commit history and status, manage branches, and connect a local repository to a remote repository on GitHub. Key points covered include initializing and cloning repositories, tracking and committing file changes, creating and deleting branches, and pushing commits to a remote origin like GitHub.

Uploaded by

Ajay Babu M
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

S.

No Command Details Notes


1 yum update -y or apt update -y Updates the server
2 yum install git -y or apt install git -y Installs the git pacakage
3 Which git Shows location of git in our server
4 git --version Displays Version of Git installed in over server
5 git config --global user.name 'XXXXXX' Used to update the user name
6 git config --global user.email 'XXXXXX' Used to update the user email
Display the global paramaters like user name, email
7 git config --list
etc.,

It can be used to convert an existing,


unversioned project to a Git repository
or initialize a new, empty repository.
8 git init The git init command creates a new Git repository.
Most other Git commands are not
available outside of an initialized
repository, so this is usually the first
command you'll run in a new project.

git clone is primarily used to point to an


existing repo and make a clone or copy
of that repo at in a new directory, at
another location.
The git clone command copies an existing Git
9 git clone
repository.
The original repository can be located
on the local filesystem or on remote
machine accessible supported
protocols.
10 Local git consists of
Where we create , modify and remove our file in local
11 i) Working Directory
m/c
12 ii) Stage / Index area
It used to add our files in Working Directory to
13 git add .
Stage/Index area
14 iii) Local Repo
It used to add our files in Stage/Index area to local
15 git commit -m "XXXXXXX"
repo
It lets you see which changes have been
staged, which haven ’ t, and which files
The git status command displays the state of the
aren’t being tracked by Git.
working directory and the staging area.
16 git status
Status output does not show you any
List which files are staged, unstaged, and untracked.
information regarding the committed
project history
gitignore - Specifies intentionally untracked files to Files already tracked by Git are not
.gitignore File
ignore affected
The git log command displays committed ID's
git log show you any information
17 git log regarding the committed project
It lets you list the project history, filter it, and search
history
for specific changes.
Say we use git log --oneline to see
commit ids
alias Used to create a short cut for a long command
now # alias glo = 'git log --oneline'
now by entering glo we get commit ids
18 git log -1 Displays last commit id
19 git log --oneline Displays list of commits
20 git log --grep "XXXX" Picks the commit with XXXXX
21 git show 'first 7 digits of commit id' Displays the details of that commit ID
Inorder to connect Local Repo to Central Repo in git
22 git remote add 'http code link'
Hub
Invoking git remote with the -v option
will print the list of bookmarked
23 git remote -v View existing remotes repository names and additionally, the
corresponding repository URL. The -v
option stands for "verbose"
24 git remote rename origin destination remote origin was renamed to destination
25 git remote rm destination remove remote destination
26 git branch Displays the branches
27 git branch xxx Create a new branch with name XXX Default branch is main
28 git checkout XXX Shifts from Main to XXX Branch
29 git merge xxx Combains data from branch XXX to main
30 git branch -m main Renames current branch name (from master to main)

31 git branch -d xxx Delete branch in local repo


32 git push origin main Moves files from local repo to Central repo
used to bring back yyy file from staging area work
33 git reset yyy
space
It will remove file from staging area & bring back the commits will be deleted & files will be
34 git reset --soft
file from staging area to work space avilable in work space
It will remove file from staging area but wont brig it to
35 git reset --hard commits as well as files also deleted
workspace
Rebasing is the process of moving or combining a
sequence of commits to a new base commit. Rebasing
git rebase
is most useful and easily visualized in the context of a
feature branching workflow.
It will delete file from workspace, stagging area.
It will generate new commit ID to local repo and we
36 git revert 'first 7 digits of commit id'
can add message regarding deleation of file in that
dialog box opened
1. How to delete local repo? By using
37 How to delete commits ?
2. How to delete remote repo? git reset --soft & git reset --hard
38 git remove 'file name' File will be removed from workspace and staging area

39 git clean -n Dry run for deleting all untracked files


40 git clean -f Deleting all untracked files
41 git pull origin xxx:main pull data from xxx branch to main

git fetch only downloads new data from a remote


repository - but it doesn't integrate any of this new git pull not only downloads new data; it
data into your working files. also directly integrates it into your
42 git fetch Vs git Pull Fetch is great for getting a fresh view on all the things current working copy files.
that happened in a remote repository. Due to it's
"harmless" nature, you can rest assured: fetch will git pull = git fetch + git merge
never manipulate, destroy, or screw up anything.

Git Rebase is going to change whole


git merge will not impact any developers because the base of the branch and move it to the
commits are in sequential order based on time stamp, head of the what ever the branch you
git merge Vs git rebase
we really know what exactly happning base on are rebasing. If you use git rebase for
commits. public branch all other are still using
old commit which will cause issues.

git clone Vs git fork


43 git push origin main:main push data from local repo to central repo
If we want to do multiple task in one file & one branch
44 git stash and also one task will not effect other task in that
condition we use git stash.
45 git stash list
46 git stash clear

In distributed version control, the only


major difference you will find here is,
instead of one single repository which
In centralized source control, there is a server and a is the server, here every single
47 client. The server is the master repository that developer or client has their own server
contains all of the versions of the code. and they will have a copy of the entire
history or version of the code and all of
its branches in their local server or
machine.

To work on any project, firstly user or client needs to Basically, every client or user can work
Centralized vs Distributed Version Control get the code from the master repository or server. So locally and disconnected which is more
48 the client communicates with the server and pulls all convenient than centralized source
the code or current version of the code from the server control and that ’ s why it is called
to their local machine. distributed.
It doesn ’ t follow the way of
communicating or merging the code
straight forward to the master
There will be just one repository and that will contain
repository after making changes. Firstly
49 all the history or version of the code and different
you commit all the changes in your own
branches of the code
server or repository and then the ‘set of
changes ’ will merge to the master
repository.
Can we share the code for two different Yes , we can share as per requirement but first we
50
branch have to add the branch
51 git cherry-pick
git secrets
for I in {1..10}
do
Shell Script for Auto Commit for create & echo $(date) > FILE$I
52
Commit 10 files git add . && git commit -m "Commiting File FILE$I"
sleep 1
done
Branching allows teams of developers to easily
A branch strategy, therefore, is the
collaborate inside of one central code base. When a
strategy that software development
developer creates a branch, the version control system
53 What is GIT Flow branch Strategy ? teams adopt when writing, merging and
creates a copy of the code base at that point in time.
deploying code when using a version
Changes to the branch don't affect other developers on
control system.
the team.
We have
1)Git Flow Branch Strategy
2) GitHub Branch Strategy
3) GitLab Branch Strategy

The Benefits of Git Flow:


1.The various types of branches make it
The main idea behind the Git flow branching strategy easy and intuitive to organize your
is to isolate your work into different types of branches. work.
There are five different branch types in total: 2.The systematic development process
1. Main allows for efficient testing.
2. Develop 3.The use of release branches allows
3. Feature you to easily and continuously support
4. Release multiple versions of production code.
1)Git Flow Branch Strategy 5. Hotfix
The Challenges of Git Flow:
The two primary branches in Git flow are main and 1.Depending on the complexity of the
develop. product, the Git flow model could
overcomplicate and slow the
There are three types of supporting branches with development process and release cycle.
different intended purposes: feature, release, and 2.Because of the long development
hotfix. cycle, Git flow is historically not able to
support Continuous Delivery or
Continuous Integration.

You might also like