0% found this document useful (0 votes)
43 views2 pages

Git Basics Rewriting Git History: Visit For More Information, Training, and Tutorials

Git is a version control system used to track changes to files and coordinate work on projects. The document provides an overview of common Git commands for initializing a repository, adding and committing files, viewing history and changes, branching and merging, and working with remote repositories. It also includes additional options and explanations for some commands.

Uploaded by

squidee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views2 pages

Git Basics Rewriting Git History: Visit For More Information, Training, and Tutorials

Git is a version control system used to track changes to files and coordinate work on projects. The document provides an overview of common Git commands for initializing a repository, adding and committing files, viewing history and changes, branching and merging, and working with remote repositories. It also includes additional options and explanations for some commands.

Uploaded by

squidee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Git Basics

Undoing Changes
git init
<directory>
git clone <repo>
git config
user.name <name>
git add
<directory>
git commit -m
"<message>"
git status
git log
git diff
Croato ompty Git ropo in spooihod dirootory. Pun witn no argumonts to
initializo tno ourront dirootory as a git ropository.
Clono ropo looatod at <ropo> onto looal maonino. Original ropo oan bo
looatod on tno looal hlosystom or on a romoto maonino via HTTP or SSH.
Oohno autnor namo to bo usod or all oommits in ourront ropo. Oovs
oommonly uso --global hag to sot oonhg options or ourront usor.
Stago all onangos in <dirootory> or tno noxt oommit. Poplaoo <dirootory>
witn a <hlo> to onango a spooiho hlo.
Commit tno stagod snapsnot, but instoad o launoning a toxt oditor, uso
<mossago> as tno oommit mossago.
List wnion hlos aro stagod, unstagod, and untraokod.
Oisplay tno ontiro oommit nistory using tno doault ormat. For
oustomization soo additional options.
Snow unstagod onangos botwoon your indox and working
dirootory
Croato now oommit tnat undoos all o tno onangos mado in
<oommit>, tnon apply it to tno ourront branon.
git revert
<commit>
Pomovo <hlo> rom tno staging aroa, but loavo tno working dirootory
unonangod. Tnis unstagos a hlo witnout ovorwriting any onangos.
git reset <file>
Snows wnion hlos would bo romovod rom working dirootory. Uso tno -
hag in plaoo o tno -n hag to oxoouto tno oloan.
git clean -n
+
Git Branches
Remote Repositories
Rewriting Git History
Poplaoo tno last oommit witn tno stagod onangos and last oommit
oombinod. Uso witn notning stagod to odit tno last oommit's mossago.
git commit --amend
Pobaso tno ourront branon onto <baso>. <baso> oan bo a oommit
O, a branon namo, a tag, or a rolativo rooronoo to HEAO.
git rebase <base>
Snow a log o onangos to tno looal ropository's HEAO. Add --rolativo-
dato hag to snow dato ino or --all to snow all ros.
git reflog
List all o tno branonos in your ropo. Add a <branon> argumont to
oroato a now branon witn tno namo <branon>.
git branch
Croato and onook out a now branon namod <branon>. Orop tno -b
hag to onookout an oxisting branon.
git checkout -b
<branch>
Morgo <branon> into tno ourront branon. git merge <branch>
Croato a now oonnootion to a romoto ropo. Ator adding a romoto, you
oan uso <namo> as a snortout or <url> in otnor oommands.
git remote add
<name> <url>
Fotonos a spooiho <branon>, rom tno ropo. Loavo o <branon> to
oton all romoto ros.
git fetch
<remote> <branch>
Foton tno spooihod romoto's oopy o ourront branon and immodiatoly
morgo it into tno looal oopy.
git pull <remote>
Pusn tno branon to <romoto>, along witn nooossary oommits and
ob|oots. Croatos namod branon in tno romoto ropo i it doosn't oxist.
git push <remote>
<branch>
Git Cheat Sheet
Visit atlassian.com/git for more information, training, and tutorials
page 1
+
+
+
+ +
+
+
git cong git di
git log
git reset
git rebase
git pull
git push
Additional Options +
Oohno tno autnor namo to bo usod or all oommits by tno ourront usor.
git config --global
user.name <name>
Oohno tno autnor omail to bo usod or all oommits by tno ourront usor.
git config --global
user.email <email>
Croato snortout or a Git oommand. E.g. alias.glog "log --graph
--oneline" will sot "git glog" oquivalont to "git log --graph --oneline"
git config --global
alias.<alias-name>
<git-command>
Sot toxt oditor usod by oommands or all usors on tno maonino. <oditor>
arg snould bo tno oommand tnat launonos tno dosirod oditor (o.g., vi).
git config --system
core.editor
<editor>
Opon tno global oonhguration hlo in a toxt oditor or manual oditing.
git config --global
--edit
git log -<limit>
git log --oneline
git log --stat
git log -p
git log
--author="<pattern>"
git log
--grep="<pattern>"
git log
<since>..<until>
git log -- <file>
git log --graph
--decorate
Limit numbor o oommits by <limit> . E.g. git log -5 will limit to 5
!"##$%&
Condonso oaon oommit to a singlo lino.
noludo wnion hlos woro altorod and tno rolativo numbor o linos tnat
woro addod or dolotod rom oaon o tnom.
Oisplay tno ull di o oaon oommit.
Soaron or oommits by a partioular autnor.
Soaron or oommits witn a oommit mossago tnat matonos
<pattorn>.
Snow oommits tnat ooour botwoon <sinoo> and <until>. Args oan bo a
oommit O, branon namo, HEAO, or any otnor kind o rovision rooronoo.
Snow dioronoo botwoon working dirootory and last oommit.
Only display oommits tnat navo tno spooihod hlo.
--grapn hag draws a toxt basod grapn o oommits on lot sido o oommit
msgs. --dooorato adds namos o branonos or tags o oommits snown.
git diff HEAD
Snow dioronoo botwoon stagod onangos and last oommit.
git diff --cached
Posot staging aroa to maton most rooont oommit, but loavo tno working
dirootory unonangod.
git reset
Posot staging aroa and working dirootory to maton most rooont oommit
and overwrites all changes in tno working dirootory.
git reset --hard
Movo tno ourront branon tip baokward to <oommit>, rosot tno staging
aroa to maton, but loavo tno working dirootory alono.
git reset <commit>
Samo as provious, but rosots botn tno staging aroa & working dirootory to
maton. Deletes unoommittod onangos, and all commits after <oommit>.
git reset --hard
<commit>
ntoraotivoly robaso ourront branon onto <baso>. Launonos oditor to ontor
oommands or now oaon oommit will bo transorrod to tno now baso.
git rebase -i
<base>
Foton tno romoto's oopy o ourront branon and robasos it into tno looal
oopy. Usos git robaso instoad o morgo to intograto tno branonos.
git pull --rebase
<remote>
Foroos tno git push ovon i it rosults in a non-ast-orward morgo. Oo not
uso tno --oroo hag unloss you'ro absolutoly suro you know wnat you'ro doing.
git push <remote>
--force
Pusn all o your looal branonos to tno spooihod romoto.
git push <remote>
--all
Tags aron't automatioally pusnod wnon you pusn a branon or uso tno
--all hag. Tno --tags hag sonds all o your looal tags to tno romoto ropo.
git push <remote>
--tags
Visit atlassian.com/git for more information, training, and tutorials
page 2

You might also like