blob: c0858b50bbb528bc53316c21111d6a71333f8377 [file]
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta name="generator" content="Asciidoctor 2.0.26"/>
<title>gittutorial(7)</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700"/>
<style>
/*! Asciidoctor default stylesheet | MIT License | https://asciidoctor.org */
/* Uncomment the following line when using as a custom stylesheet */
/* @import "https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700"; */
html{font-family:sans-serif;-webkit-text-size-adjust:100%}
a{background:none}
a:focus{outline:thin dotted}
a:active,a:hover{outline:0}
h1{font-size:2em;margin:.67em 0}
b,strong{font-weight:bold}
abbr{font-size:.9em}
abbr[title]{cursor:help;border-bottom:1px dotted #dddddf;text-decoration:none}
dfn{font-style:italic}
hr{height:0}
mark{background:#ff0;color:#000}
code,kbd,pre,samp{font-family:monospace;font-size:1em}
pre{white-space:pre-wrap}
q{quotes:"\201C" "\201D" "\2018" "\2019"}
small{font-size:80%}
sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}
sup{top:-.5em}
sub{bottom:-.25em}
img{border:0}
svg:not(:root){overflow:hidden}
figure{margin:0}
audio,video{display:inline-block}
audio:not([controls]){display:none;height:0}
fieldset{border:1px solid silver;margin:0 2px;padding:.35em .625em .75em}
legend{border:0;padding:0}
button,input,select,textarea{font-family:inherit;font-size:100%;margin:0}
button,input{line-height:normal}
button,select{text-transform:none}
button,html input[type=button],input[type=reset],input[type=submit]{-webkit-appearance:button;cursor:pointer}
button[disabled],html input[disabled]{cursor:default}
input[type=checkbox],input[type=radio]{padding:0}
button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}
textarea{overflow:auto;vertical-align:top}
table{border-collapse:collapse;border-spacing:0}
*,::before,::after{box-sizing:border-box}
html,body{font-size:100%}
body{background:#fff;color:rgba(0,0,0,.8);padding:0;margin:0;font-family:"Noto Serif","DejaVu Serif",serif;line-height:1;position:relative;cursor:auto;-moz-tab-size:4;-o-tab-size:4;tab-size:4;word-wrap:anywhere;-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased}
a:hover{cursor:pointer}
img,object,embed{max-width:100%;height:auto}
object,embed{height:100%}
img{-ms-interpolation-mode:bicubic}
.left{float:left!important}
.right{float:right!important}
.text-left{text-align:left!important}
.text-right{text-align:right!important}
.text-center{text-align:center!important}
.text-justify{text-align:justify!important}
.hide{display:none}
img,object,svg{display:inline-block;vertical-align:middle}
textarea{height:auto;min-height:50px}
select{width:100%}
.subheader,.admonitionblock td.content>.title,.audioblock>.title,.exampleblock>.title,.imageblock>.title,.listingblock>.title,.literalblock>.title,.stemblock>.title,.openblock>.title,.paragraph>.title,.quoteblock>.title,table.tableblock>.title,.verseblock>.title,.videoblock>.title,.dlist>.title,.olist>.title,.ulist>.title,.qlist>.title,.hdlist>.title{line-height:1.45;color:#7a2518;font-weight:400;margin-top:0;margin-bottom:.25em}
div,dl,dt,dd,ul,ol,li,h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6,pre,form,p,blockquote,th,td{margin:0;padding:0}
a{color:#2156a5;text-decoration:underline;line-height:inherit}
a:hover,a:focus{color:#1d4b8f}
a img{border:0}
p{line-height:1.6;margin-bottom:1.25em;text-rendering:optimizeLegibility}
p aside{font-size:.875em;line-height:1.35;font-style:italic}
h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{font-family:"Open Sans","DejaVu Sans",sans-serif;font-weight:300;font-style:normal;color:#ba3925;text-rendering:optimizeLegibility;margin-top:1em;margin-bottom:.5em;line-height:1.0125em}
h1 small,h2 small,h3 small,#toctitle small,.sidebarblock>.content>.title small,h4 small,h5 small,h6 small{font-size:60%;color:#e99b8f;line-height:0}
h1{font-size:2.125em}
h2{font-size:1.6875em}
h3,#toctitle,.sidebarblock>.content>.title{font-size:1.375em}
h4,h5{font-size:1.125em}
h6{font-size:1em}
hr{border:solid #dddddf;border-width:1px 0 0;clear:both;margin:1.25em 0 1.1875em}
em,i{font-style:italic;line-height:inherit}
strong,b{font-weight:bold;line-height:inherit}
small{font-size:60%;line-height:inherit}
code{font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;font-weight:400;color:rgba(0,0,0,.9)}
ul,ol,dl{line-height:1.6;margin-bottom:1.25em;list-style-position:outside;font-family:inherit}
ul,ol{margin-left:1.5em}
ul li ul,ul li ol{margin-left:1.25em;margin-bottom:0}
ul.circle{list-style-type:circle}
ul.disc{list-style-type:disc}
ul.square{list-style-type:square}
ul.circle ul:not([class]),ul.disc ul:not([class]),ul.square ul:not([class]){list-style:inherit}
ol li ul,ol li ol{margin-left:1.25em;margin-bottom:0}
dl dt{margin-bottom:.3125em;font-weight:bold}
dl dd{margin-bottom:1.25em}
blockquote{margin:0 0 1.25em;padding:.5625em 1.25em 0 1.1875em;border-left:1px solid #ddd}
blockquote,blockquote p{line-height:1.6;color:rgba(0,0,0,.85)}
@media screen and (min-width:768px){h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{line-height:1.2}
h1{font-size:2.75em}
h2{font-size:2.3125em}
h3,#toctitle,.sidebarblock>.content>.title{font-size:1.6875em}
h4{font-size:1.4375em}}
table{background:#fff;margin-bottom:1.25em;border:1px solid #dedede;word-wrap:normal}
table thead,table tfoot{background:#f7f8f7}
table thead tr th,table thead tr td,table tfoot tr th,table tfoot tr td{padding:.5em .625em .625em;font-size:inherit;color:rgba(0,0,0,.8);text-align:left}
table tr th,table tr td{padding:.5625em .625em;font-size:inherit;color:rgba(0,0,0,.8)}
table tr.even,table tr.alt{background:#f8f8f7}
table thead tr th,table tfoot tr th,table tbody tr td,table tr td,table tfoot tr td{line-height:1.6}
h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{line-height:1.2;word-spacing:-.05em}
h1 strong,h2 strong,h3 strong,#toctitle strong,.sidebarblock>.content>.title strong,h4 strong,h5 strong,h6 strong{font-weight:400}
.center{margin-left:auto;margin-right:auto}
.stretch{width:100%}
.clearfix::before,.clearfix::after,.float-group::before,.float-group::after{content:" ";display:table}
.clearfix::after,.float-group::after{clear:both}
:not(pre).nobreak{word-wrap:normal}
:not(pre).nowrap{white-space:nowrap}
:not(pre).pre-wrap{white-space:pre-wrap}
:not(pre):not([class^=L])>code{font-size:.9375em;font-style:normal!important;letter-spacing:0;padding:.1em .5ex;word-spacing:-.15em;background:#f7f7f8;border-radius:4px;line-height:1.45;text-rendering:optimizeSpeed}
pre{color:rgba(0,0,0,.9);font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;line-height:1.45;text-rendering:optimizeSpeed}
pre code,pre pre{color:inherit;font-size:inherit;line-height:inherit}
pre.nowrap,pre.nowrap pre{white-space:pre;word-wrap:normal}
em em{font-style:normal}
strong strong{font-weight:400}
.keyseq{color:rgba(51,51,51,.8)}
kbd{font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;display:inline-block;color:rgba(0,0,0,.8);font-size:.65em;line-height:1.45;background:#f7f7f7;border:1px solid #ccc;border-radius:3px;box-shadow:0 1px 0 rgba(0,0,0,.2),inset 0 0 0 .1em #fff;margin:0 .15em;padding:.2em .5em;vertical-align:middle;position:relative;top:-.1em;white-space:nowrap}
.keyseq kbd:first-child{margin-left:0}
.keyseq kbd:last-child{margin-right:0}
.menuseq,.menuref{color:#000}
.menuseq b:not(.caret),.menuref{font-weight:inherit}
.menuseq{word-spacing:-.02em}
.menuseq b.caret{font-size:1.25em;line-height:.8}
.menuseq i.caret{font-weight:bold;text-align:center;width:.45em}
b.button::before,b.button::after{position:relative;top:-1px;font-weight:400}
b.button::before{content:"[";padding:0 3px 0 2px}
b.button::after{content:"]";padding:0 2px 0 3px}
p a>code:hover{color:rgba(0,0,0,.9)}
#header,#content,#footnotes,#footer{width:100%;margin:0 auto;max-width:62.5em;*zoom:1;position:relative;padding-left:.9375em;padding-right:.9375em}
#header::before,#header::after,#content::before,#content::after,#footnotes::before,#footnotes::after,#footer::before,#footer::after{content:" ";display:table}
#header::after,#content::after,#footnotes::after,#footer::after{clear:both}
#content{margin-top:1.25em}
#content::before{content:none}
#header>h1:first-child{color:rgba(0,0,0,.85);margin-top:2.25rem;margin-bottom:0}
#header>h1:first-child+#toc{margin-top:8px;border-top:1px solid #dddddf}
#header>h1:only-child{border-bottom:1px solid #dddddf;padding-bottom:8px}
#header .details{border-bottom:1px solid #dddddf;line-height:1.45;padding-top:.25em;padding-bottom:.25em;padding-left:.25em;color:rgba(0,0,0,.6);display:flex;flex-flow:row wrap}
#header .details span:first-child{margin-left:-.125em}
#header .details span.email a{color:rgba(0,0,0,.85)}
#header .details br{display:none}
#header .details br+span::before{content:"\00a0\2013\00a0"}
#header .details br+span.author::before{content:"\00a0\22c5\00a0";color:rgba(0,0,0,.85)}
#header .details br+span#revremark::before{content:"\00a0|\00a0"}
#header #revnumber{text-transform:capitalize}
#header #revnumber::after{content:"\00a0"}
#content>h1:first-child:not([class]){color:rgba(0,0,0,.85);border-bottom:1px solid #dddddf;padding-bottom:8px;margin-top:0;padding-top:1rem;margin-bottom:1.25rem}
#toc{border-bottom:1px solid #e7e7e9;padding-bottom:.5em}
#toc>ul{margin-left:.125em}
#toc ul.sectlevel0>li>a{font-style:italic}
#toc ul.sectlevel0 ul.sectlevel1{margin:.5em 0}
#toc ul{font-family:"Open Sans","DejaVu Sans",sans-serif;list-style-type:none}
#toc li{line-height:1.3334;margin-top:.3334em}
#toc a{text-decoration:none}
#toc a:active{text-decoration:underline}
#toctitle{color:#7a2518;font-size:1.2em}
@media screen and (min-width:768px){#toctitle{font-size:1.375em}
body.toc2{padding-left:15em;padding-right:0}
body.toc2 #header>h1:nth-last-child(2){border-bottom:1px solid #dddddf;padding-bottom:8px}
#toc.toc2{margin-top:0!important;background:#f8f8f7;position:fixed;width:15em;left:0;top:0;border-right:1px solid #e7e7e9;border-top-width:0!important;border-bottom-width:0!important;z-index:1000;padding:1.25em 1em;height:100%;overflow:auto}
#toc.toc2 #toctitle{margin-top:0;margin-bottom:.8rem;font-size:1.2em}
#toc.toc2>ul{font-size:.9em;margin-bottom:0}
#toc.toc2 ul ul{margin-left:0;padding-left:1em}
#toc.toc2 ul.sectlevel0 ul.sectlevel1{padding-left:0;margin-top:.5em;margin-bottom:.5em}
body.toc2.toc-right{padding-left:0;padding-right:15em}
body.toc2.toc-right #toc.toc2{border-right-width:0;border-left:1px solid #e7e7e9;left:auto;right:0}}
@media screen and (min-width:1280px){body.toc2{padding-left:20em;padding-right:0}
#toc.toc2{width:20em}
#toc.toc2 #toctitle{font-size:1.375em}
#toc.toc2>ul{font-size:.95em}
#toc.toc2 ul ul{padding-left:1.25em}
body.toc2.toc-right{padding-left:0;padding-right:20em}}
#content #toc{border:1px solid #e0e0dc;margin-bottom:1.25em;padding:1.25em;background:#f8f8f7;border-radius:4px}
#content #toc>:first-child{margin-top:0}
#content #toc>:last-child{margin-bottom:0}
#footer{max-width:none;background:rgba(0,0,0,.8);padding:1.25em}
#footer-text{color:hsla(0,0%,100%,.8);line-height:1.44}
#content{margin-bottom:.625em}
.sect1{padding-bottom:.625em}
@media screen and (min-width:768px){#content{margin-bottom:1.25em}
.sect1{padding-bottom:1.25em}}
.sect1:last-child{padding-bottom:0}
.sect1+.sect1{border-top:1px solid #e7e7e9}
#content h1>a.anchor,h2>a.anchor,h3>a.anchor,#toctitle>a.anchor,.sidebarblock>.content>.title>a.anchor,h4>a.anchor,h5>a.anchor,h6>a.anchor{position:absolute;z-index:1001;width:1.5ex;margin-left:-1.5ex;display:block;text-decoration:none!important;visibility:hidden;text-align:center;font-weight:400}
#content h1>a.anchor::before,h2>a.anchor::before,h3>a.anchor::before,#toctitle>a.anchor::before,.sidebarblock>.content>.title>a.anchor::before,h4>a.anchor::before,h5>a.anchor::before,h6>a.anchor::before{content:"\00A7";font-size:.85em;display:block;padding-top:.1em}
#content h1:hover>a.anchor,#content h1>a.anchor:hover,h2:hover>a.anchor,h2>a.anchor:hover,h3:hover>a.anchor,#toctitle:hover>a.anchor,.sidebarblock>.content>.title:hover>a.anchor,h3>a.anchor:hover,#toctitle>a.anchor:hover,.sidebarblock>.content>.title>a.anchor:hover,h4:hover>a.anchor,h4>a.anchor:hover,h5:hover>a.anchor,h5>a.anchor:hover,h6:hover>a.anchor,h6>a.anchor:hover{visibility:visible}
#content h1>a.link,h2>a.link,h3>a.link,#toctitle>a.link,.sidebarblock>.content>.title>a.link,h4>a.link,h5>a.link,h6>a.link{color:#ba3925;text-decoration:none}
#content h1>a.link:hover,h2>a.link:hover,h3>a.link:hover,#toctitle>a.link:hover,.sidebarblock>.content>.title>a.link:hover,h4>a.link:hover,h5>a.link:hover,h6>a.link:hover{color:#a53221}
details,.audioblock,.imageblock,.literalblock,.listingblock,.stemblock,.videoblock{margin-bottom:1.25em}
details{margin-left:1.25rem}
details>summary{cursor:pointer;display:block;position:relative;line-height:1.6;margin-bottom:.625rem;outline:none;-webkit-tap-highlight-color:transparent}
details>summary::-webkit-details-marker{display:none}
details>summary::before{content:"";border:solid transparent;border-left:solid;border-width:.3em 0 .3em .5em;position:absolute;top:.5em;left:-1.25rem;transform:translateX(15%)}
details[open]>summary::before{border:solid transparent;border-top:solid;border-width:.5em .3em 0;transform:translateY(15%)}
details>summary::after{content:"";width:1.25rem;height:1em;position:absolute;top:.3em;left:-1.25rem}
.admonitionblock td.content>.title,.audioblock>.title,.exampleblock>.title,.imageblock>.title,.listingblock>.title,.literalblock>.title,.stemblock>.title,.openblock>.title,.paragraph>.title,.quoteblock>.title,table.tableblock>.title,.verseblock>.title,.videoblock>.title,.dlist>.title,.olist>.title,.ulist>.title,.qlist>.title,.hdlist>.title{text-rendering:optimizeLegibility;text-align:left;font-family:"Noto Serif","DejaVu Serif",serif;font-size:1rem;font-style:italic}
table.tableblock.fit-content>caption.title{white-space:nowrap;width:0}
.paragraph.lead>p,#preamble>.sectionbody>[class=paragraph]:first-of-type p{font-size:1.21875em;line-height:1.6;color:rgba(0,0,0,.85)}
.admonitionblock>table{border-collapse:separate;border:0;background:none;width:100%}
.admonitionblock>table td.icon{text-align:center;width:80px}
.admonitionblock>table td.icon img{max-width:none}
.admonitionblock>table td.icon .title{font-weight:bold;font-family:"Open Sans","DejaVu Sans",sans-serif;text-transform:uppercase}
.admonitionblock>table td.content{padding-left:1.125em;padding-right:1.25em;border-left:1px solid #dddddf;color:rgba(0,0,0,.6);word-wrap:anywhere}
.admonitionblock>table td.content>:last-child>:last-child{margin-bottom:0}
.exampleblock>.content{border:1px solid #e6e6e6;margin-bottom:1.25em;padding:1.25em;background:#fff;border-radius:4px}
.sidebarblock{border:1px solid #dbdbd6;margin-bottom:1.25em;padding:1.25em;background:#f3f3f2;border-radius:4px}
.sidebarblock>.content>.title{color:#7a2518;margin-top:0;text-align:center}
.exampleblock>.content>:first-child,.sidebarblock>.content>:first-child{margin-top:0}
.exampleblock>.content>:last-child,.exampleblock>.content>:last-child>:last-child,.exampleblock>.content .olist>ol>li:last-child>:last-child,.exampleblock>.content .ulist>ul>li:last-child>:last-child,.exampleblock>.content .qlist>ol>li:last-child>:last-child,.sidebarblock>.content>:last-child,.sidebarblock>.content>:last-child>:last-child,.sidebarblock>.content .olist>ol>li:last-child>:last-child,.sidebarblock>.content .ulist>ul>li:last-child>:last-child,.sidebarblock>.content .qlist>ol>li:last-child>:last-child{margin-bottom:0}
.literalblock pre,.listingblock>.content>pre{border-radius:4px;overflow-x:auto;padding:1em;font-size:.8125em}
@media screen and (min-width:768px){.literalblock pre,.listingblock>.content>pre{font-size:.90625em}}
@media screen and (min-width:1280px){.literalblock pre,.listingblock>.content>pre{font-size:1em}}
.literalblock pre,.listingblock>.content>pre:not(.highlight),.listingblock>.content>pre[class=highlight],.listingblock>.content>pre[class^="highlight "]{background:#f7f7f8}
.literalblock.output pre{color:#f7f7f8;background:rgba(0,0,0,.9)}
.listingblock>.content{position:relative}
.listingblock pre>code{display:block}
.listingblock code[data-lang]::before{display:none;content:attr(data-lang);position:absolute;font-size:.75em;top:.425rem;right:.5rem;line-height:1;text-transform:uppercase;color:inherit;opacity:.5}
.listingblock:hover code[data-lang]::before{display:block}
.listingblock.terminal pre .command::before{content:attr(data-prompt);padding-right:.5em;color:inherit;opacity:.5}
.listingblock.terminal pre .command:not([data-prompt])::before{content:"$"}
.listingblock pre.highlightjs{padding:0}
.listingblock pre.highlightjs>code{padding:1em;border-radius:4px}
.listingblock pre.prettyprint{border-width:0}
.prettyprint{background:#f7f7f8}
pre.prettyprint .linenums{line-height:1.45;margin-left:2em}
pre.prettyprint li{background:none;list-style-type:inherit;padding-left:0}
pre.prettyprint li code[data-lang]::before{opacity:1}
pre.prettyprint li:not(:first-child) code[data-lang]::before{display:none}
table.linenotable{border-collapse:separate;border:0;margin-bottom:0;background:none}
table.linenotable td[class]{color:inherit;vertical-align:top;padding:0;line-height:inherit;white-space:normal}
table.linenotable td.code{padding-left:.75em}
table.linenotable td.linenos,pre.pygments .linenos{border-right:1px solid;opacity:.35;padding-right:.5em;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}
pre.pygments span.linenos{display:inline-block;margin-right:.75em}
.quoteblock{margin:0 1em 1.25em 1.5em;display:table}
.quoteblock:not(.excerpt)>.title{margin-left:-1.5em;margin-bottom:.75em}
.quoteblock blockquote,.quoteblock p{color:rgba(0,0,0,.85);font-size:1.15rem;line-height:1.75;word-spacing:.1em;letter-spacing:0;font-style:italic;text-align:justify}
.quoteblock blockquote{margin:0;padding:0;border:0}
.quoteblock blockquote::before{content:"\201c";float:left;font-size:2.75em;font-weight:bold;line-height:.6em;margin-left:-.6em;color:#7a2518;text-shadow:0 1px 2px rgba(0,0,0,.1)}
.quoteblock blockquote>.paragraph:last-child p{margin-bottom:0}
.quoteblock .attribution{margin-top:.75em;margin-right:.5ex;text-align:right}
.verseblock{margin:0 1em 1.25em}
.verseblock pre{font-family:"Open Sans","DejaVu Sans",sans-serif;font-size:1.15rem;color:rgba(0,0,0,.85);font-weight:300;text-rendering:optimizeLegibility}
.verseblock pre strong{font-weight:400}
.verseblock .attribution{margin-top:1.25rem;margin-left:.5ex}
.quoteblock .attribution,.verseblock .attribution{font-size:.9375em;line-height:1.45;font-style:italic}
.quoteblock .attribution br,.verseblock .attribution br{display:none}
.quoteblock .attribution cite,.verseblock .attribution cite{display:block;letter-spacing:-.025em;color:rgba(0,0,0,.6)}
.quoteblock.abstract blockquote::before,.quoteblock.excerpt blockquote::before,.quoteblock .quoteblock blockquote::before{display:none}
.quoteblock.abstract blockquote,.quoteblock.abstract p,.quoteblock.excerpt blockquote,.quoteblock.excerpt p,.quoteblock .quoteblock blockquote,.quoteblock .quoteblock p{line-height:1.6;word-spacing:0}
.quoteblock.abstract{margin:0 1em 1.25em;display:block}
.quoteblock.abstract>.title{margin:0 0 .375em;font-size:1.15em;text-align:center}
.quoteblock.excerpt>blockquote,.quoteblock .quoteblock{padding:0 0 .25em 1em;border-left:.25em solid #dddddf}
.quoteblock.excerpt,.quoteblock .quoteblock{margin-left:0}
.quoteblock.excerpt blockquote,.quoteblock.excerpt p,.quoteblock .quoteblock blockquote,.quoteblock .quoteblock p{color:inherit;font-size:1.0625rem}
.quoteblock.excerpt .attribution,.quoteblock .quoteblock .attribution{color:inherit;font-size:.85rem;text-align:left;margin-right:0}
p.tableblock:last-child{margin-bottom:0}
td.tableblock>.content{margin-bottom:1.25em;word-wrap:anywhere}
td.tableblock>.content>:last-child{margin-bottom:-1.25em}
table.tableblock,th.tableblock,td.tableblock{border:0 solid #dedede}
table.grid-all>*>tr>*{border-width:1px}
table.grid-cols>*>tr>*{border-width:0 1px}
table.grid-rows>*>tr>*{border-width:1px 0}
table.frame-all{border-width:1px}
table.frame-ends{border-width:1px 0}
table.frame-sides{border-width:0 1px}
table.frame-none>colgroup+*>:first-child>*,table.frame-sides>colgroup+*>:first-child>*{border-top-width:0}
table.frame-none>:last-child>:last-child>*,table.frame-sides>:last-child>:last-child>*{border-bottom-width:0}
table.frame-none>*>tr>:first-child,table.frame-ends>*>tr>:first-child{border-left-width:0}
table.frame-none>*>tr>:last-child,table.frame-ends>*>tr>:last-child{border-right-width:0}
table.stripes-all>*>tr,table.stripes-odd>*>tr:nth-of-type(odd),table.stripes-even>*>tr:nth-of-type(even),table.stripes-hover>*>tr:hover{background:#f8f8f7}
th.halign-left,td.halign-left{text-align:left}
th.halign-right,td.halign-right{text-align:right}
th.halign-center,td.halign-center{text-align:center}
th.valign-top,td.valign-top{vertical-align:top}
th.valign-bottom,td.valign-bottom{vertical-align:bottom}
th.valign-middle,td.valign-middle{vertical-align:middle}
table thead th,table tfoot th{font-weight:bold}
tbody tr th{background:#f7f8f7}
tbody tr th,tbody tr th p,tfoot tr th,tfoot tr th p{color:rgba(0,0,0,.8);font-weight:bold}
p.tableblock>code:only-child{background:none;padding:0}
p.tableblock{font-size:1em}
ol{margin-left:1.75em}
ul li ol{margin-left:1.5em}
dl dd{margin-left:1.125em}
dl dd:last-child,dl dd:last-child>:last-child{margin-bottom:0}
li p,ul dd,ol dd,.olist .olist,.ulist .ulist,.ulist .olist,.olist .ulist{margin-bottom:.625em}
ul.checklist,ul.none,ol.none,ul.no-bullet,ol.no-bullet,ol.unnumbered,ul.unstyled,ol.unstyled{list-style-type:none}
ul.no-bullet,ol.no-bullet,ol.unnumbered{margin-left:.625em}
ul.unstyled,ol.unstyled{margin-left:0}
li>p:empty:only-child::before{content:"";display:inline-block}
ul.checklist>li>p:first-child{margin-left:-1em}
ul.checklist>li>p:first-child>.fa-square-o:first-child,ul.checklist>li>p:first-child>.fa-check-square-o:first-child{width:1.25em;font-size:.8em;position:relative;bottom:.125em}
ul.checklist>li>p:first-child>input[type=checkbox]:first-child{margin-right:.25em}
ul.inline{display:flex;flex-flow:row wrap;list-style:none;margin:0 0 .625em -1.25em}
ul.inline>li{margin-left:1.25em}
.unstyled dl dt{font-weight:400;font-style:normal}
ol.arabic{list-style-type:decimal}
ol.decimal{list-style-type:decimal-leading-zero}
ol.loweralpha{list-style-type:lower-alpha}
ol.upperalpha{list-style-type:upper-alpha}
ol.lowerroman{list-style-type:lower-roman}
ol.upperroman{list-style-type:upper-roman}
ol.lowergreek{list-style-type:lower-greek}
.hdlist>table,.colist>table{border:0;background:none}
.hdlist>table>tbody>tr,.colist>table>tbody>tr{background:none}
td.hdlist1,td.hdlist2{vertical-align:top;padding:0 .625em}
td.hdlist1{font-weight:bold;padding-bottom:1.25em}
td.hdlist2{word-wrap:anywhere}
.literalblock+.colist,.listingblock+.colist{margin-top:-.5em}
.colist td:not([class]):first-child{padding:.4em .75em 0;line-height:1;vertical-align:top}
.colist td:not([class]):first-child img{max-width:none}
.colist td:not([class]):last-child{padding:.25em 0}
.thumb,.th{line-height:0;display:inline-block;border:4px solid #fff;box-shadow:0 0 0 1px #ddd}
.imageblock.left{margin:.25em .625em 1.25em 0}
.imageblock.right{margin:.25em 0 1.25em .625em}
.imageblock>.title{margin-bottom:0}
.imageblock.thumb,.imageblock.th{border-width:6px}
.imageblock.thumb>.title,.imageblock.th>.title{padding:0 .125em}
.image.left,.image.right{margin-top:.25em;margin-bottom:.25em;display:inline-block;line-height:0}
.image.left{margin-right:.625em}
.image.right{margin-left:.625em}
a.image{text-decoration:none;display:inline-block}
a.image object{pointer-events:none}
sup.footnote,sup.footnoteref{font-size:.875em;position:static;vertical-align:super}
sup.footnote a,sup.footnoteref a{text-decoration:none}
sup.footnote a:active,sup.footnoteref a:active,#footnotes .footnote a:first-of-type:active{text-decoration:underline}
#footnotes{padding-top:.75em;padding-bottom:.75em;margin-bottom:.625em}
#footnotes hr{width:20%;min-width:6.25em;margin:-.25em 0 .75em;border-width:1px 0 0}
#footnotes .footnote{padding:0 .375em 0 .225em;line-height:1.3334;font-size:.875em;margin-left:1.2em;margin-bottom:.2em}
#footnotes .footnote a:first-of-type{font-weight:bold;text-decoration:none;margin-left:-1.05em}
#footnotes .footnote:last-of-type{margin-bottom:0}
#content #footnotes{margin-top:-.625em;margin-bottom:0;padding:.75em 0}
div.unbreakable{page-break-inside:avoid}
.big{font-size:larger}
.small{font-size:smaller}
.underline{text-decoration:underline}
.overline{text-decoration:overline}
.line-through{text-decoration:line-through}
.aqua{color:#00bfbf}
.aqua-background{background:#00fafa}
.black{color:#000}
.black-background{background:#000}
.blue{color:#0000bf}
.blue-background{background:#0000fa}
.fuchsia{color:#bf00bf}
.fuchsia-background{background:#fa00fa}
.gray{color:#606060}
.gray-background{background:#7d7d7d}
.green{color:#006000}
.green-background{background:#007d00}
.lime{color:#00bf00}
.lime-background{background:#00fa00}
.maroon{color:#600000}
.maroon-background{background:#7d0000}
.navy{color:#000060}
.navy-background{background:#00007d}
.olive{color:#606000}
.olive-background{background:#7d7d00}
.purple{color:#600060}
.purple-background{background:#7d007d}
.red{color:#bf0000}
.red-background{background:#fa0000}
.silver{color:#909090}
.silver-background{background:#bcbcbc}
.teal{color:#006060}
.teal-background{background:#007d7d}
.white{color:#bfbfbf}
.white-background{background:#fafafa}
.yellow{color:#bfbf00}
.yellow-background{background:#fafa00}
span.icon>.fa{cursor:default}
a span.icon>.fa{cursor:inherit}
.admonitionblock td.icon [class^="fa icon-"]{font-size:2.5em;text-shadow:1px 1px 2px rgba(0,0,0,.5);cursor:default}
.admonitionblock td.icon .icon-note::before{content:"\f05a";color:#19407c}
.admonitionblock td.icon .icon-tip::before{content:"\f0eb";text-shadow:1px 1px 2px rgba(155,155,0,.8);color:#111}
.admonitionblock td.icon .icon-warning::before{content:"\f071";color:#bf6900}
.admonitionblock td.icon .icon-caution::before{content:"\f06d";color:#bf3400}
.admonitionblock td.icon .icon-important::before{content:"\f06a";color:#bf0000}
.conum[data-value]{display:inline-block;color:#fff!important;background:rgba(0,0,0,.8);border-radius:50%;text-align:center;font-size:.75em;width:1.67em;height:1.67em;line-height:1.67em;font-family:"Open Sans","DejaVu Sans",sans-serif;font-style:normal;font-weight:bold}
.conum[data-value] *{color:#fff!important}
.conum[data-value]+b{display:none}
.conum[data-value]::after{content:attr(data-value)}
pre .conum[data-value]{position:relative;top:-.125em}
b.conum *{color:inherit!important}
.conum:not([data-value]):empty{display:none}
dt,th.tableblock,td.content,div.footnote{text-rendering:optimizeLegibility}
h1,h2,p,td.content,span.alt,summary{letter-spacing:-.01em}
p strong,td.content strong,div.footnote strong{letter-spacing:-.005em}
p,blockquote,dt,td.content,td.hdlist1,span.alt,summary{font-size:1.0625rem}
p{margin-bottom:1.25rem}
.sidebarblock p,.sidebarblock dt,.sidebarblock td.content,p.tableblock{font-size:1em}
.exampleblock>.content{background:#fffef7;border-color:#e0e0dc;box-shadow:0 1px 4px #e0e0dc}
.print-only{display:none!important}
@page{margin:1.25cm .75cm}
@media print{*{box-shadow:none!important;text-shadow:none!important}
html{font-size:80%}
a{color:inherit!important;text-decoration:underline!important}
a.bare,a[href^="#"],a[href^="mailto:"]{text-decoration:none!important}
a[href^="http:"]:not(.bare)::after,a[href^="https:"]:not(.bare)::after{content:"(" attr(href) ")";display:inline-block;font-size:.875em;padding-left:.25em}
abbr[title]{border-bottom:1px dotted}
abbr[title]::after{content:" (" attr(title) ")"}
pre,blockquote,tr,img,object,svg{page-break-inside:avoid}
thead{display:table-header-group}
svg{max-width:100%}
p,blockquote,dt,td.content{font-size:1em;orphans:3;widows:3}
h2,h3,#toctitle,.sidebarblock>.content>.title{page-break-after:avoid}
#header,#content,#footnotes,#footer{max-width:none}
#toc,.sidebarblock,.exampleblock>.content{background:none!important}
#toc{border-bottom:1px solid #dddddf!important;padding-bottom:0!important}
body.book #header{text-align:center}
body.book #header>h1:first-child{border:0!important;margin:2.5em 0 1em}
body.book #header .details{border:0!important;display:block;padding:0!important}
body.book #header .details span:first-child{margin-left:0!important}
body.book #header .details br{display:block}
body.book #header .details br+span::before{content:none!important}
body.book #toc{border:0!important;text-align:left!important;padding:0!important;margin:0!important}
body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-break-before:always}
.listingblock code[data-lang]::before{display:block}
#footer{padding:0 .9375em}
.hide-on-print{display:none!important}
.print-only{display:block!important}
.hide-for-print{display:none!important}
.show-for-print{display:inherit!important}}
@media amzn-kf8,print{#header>h1:first-child{margin-top:1.25rem}
.sect1{padding:0!important}
.sect1+.sect1{border:0}
#footer{background:none}
#footer-text{color:rgba(0,0,0,.6);font-size:.9em}}
@media amzn-kf8{#header,#content,#footnotes,#footer{padding:0}}
</style>
<style>
pre>code {
display: inline;
}
</style>
</head>
<body class="manpage">
<div id="header">
<h1>gittutorial(7) Manual Page</h1>
<h2 id="_name">NAME</h2>
<div class="sectionbody">
<p>gittutorial - Introduction to Git for beginners</p>
</div>
</div>
<div id="content">
<div class="sect1">
<h2 id="_description">DESCRIPTION</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Git is a program that lets you collaborate with others on code, back up
your code, roll back to an earlier version of your project, track how
your project has changed over time, and much more.</p>
</div>
<div class="paragraph">
<p>This tutorial explains how to create a new Git project, make
changes to it, and upload the project to the Internet. It usually takes
less than an hour if you have a little previous experience with Git, and
1-2 hours if not.</p>
</div>
<div class="paragraph">
<p>We&#8217;ll show you how to use the commands <code>git</code> <code>commit</code>, <code>git</code> <code>add</code>,
<code>git</code> <code>diff</code>, <code>git</code> <code>status</code>, and <code>git</code> <code>push</code>.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_what_well_be_doing">What we&#8217;ll be doing</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Git lets you take snapshots of your code, like a checkpoint in a video
game. These snapshots are called "commits". Which files to save in a
commit is up to you.</p>
</div>
<div class="paragraph">
<p>When Git stores a commit, it stores a copy of every file in the commit
in a database in a folder called .<code>git</code>. This is called a "Git repository".</p>
</div>
<div class="paragraph">
<p>In this tutorial we&#8217;re going to show you how to:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Create a Git repository in a folder with the command <code>git</code> <code>init</code>.
This creates the .<code>git</code> folder where Git stores all your commits.</p>
</li>
<li>
<p>Tell Git which files you want to put in a commit</p>
</li>
<li>
<p>Make a commit</p>
</li>
<li>
<p>Change a file and make a new commit with the new version</p>
</li>
<li>
<p>Make experimental changes and throw them away</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>We&#8217;ll also explain how to use Git to put your code on the Internet.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_command_line_vs_graphical_interfaces">Command line vs graphical interfaces</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Git is a command line program, but there are many graphical interfaces
for Git built by the community. Your text editor might even have a
built-in Git integration.</p>
</div>
<div class="paragraph">
<p>In this tutorial, we&#8217;ll give instructions for using Git from the
command line. We can&#8217;t give you instructions for how to do it in your
graphical interface because there are so many of them.</p>
</div>
<div class="paragraph">
<p>You can always switch back and forth between using the command line and
a graphical interface at any time.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_step_1_make_sure_git_is_installed">Step 1: Make sure Git is installed</h2>
<div class="sectionbody">
<div class="paragraph">
<p>To do this tutorial, you&#8217;ll need:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Git to be installed. You might already have it installed,
and if not there are directions at <a href="https://git-scm.com/install/" class="bare">https://git-scm.com/install/</a></p>
</li>
<li>
<p>A terminal to use. On Windows, you can use Git Bash which comes
when you install Git.</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>You can check if Git is installed by running this in your terminal:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ git --version</pre>
</div>
</div>
<div class="paragraph">
<p>It should output something like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>git version 2.54.0</pre>
</div>
</div>
<div class="paragraph">
<p>The exact version isn&#8217;t too important: this tutorial is designed to work
with any version of Git after 2.23.0.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="step_2">Step 2: Introduce yourself to Git</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The first time you use Git on a computer, it&#8217;s a good idea to tell Git
your name and public email address. If you don&#8217;t, you&#8217;ll get a lot of
warnings from Git. To do this, run:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ git config --global user.name "Namey McName"
$ git config --global user.email you@example.com</pre>
</div>
</div>
<div class="paragraph">
<p>The name and email is so that other people you&#8217;re collaborating with
can know who made the changes. You can set them to anything you want.</p>
</div>
<div class="paragraph">
<p>To check if the name and email have been set, you can run these
commands. They should display your name and email:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ git config user.name
$ git config user.email</pre>
</div>
</div>
<div class="paragraph">
<p>Next, configure Git to set the default branch name to <code>main</code> (instead
of <code>master</code>) by running this command. We can&#8217;t explain what a branch is
yet, but Git is going to
<a href="https://sfconservancy.org/news/2020/jun/23/gitbranchname/">make <code>main</code> the default soon</a>,
and setting this avoids some extremely annoying problems in Step 14.</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ git config --global init.defaultBranch main</pre>
</div>
</div>
<div class="paragraph">
<p>If there&#8217;s no output, then it succeeded.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<div class="title">Note</div>
</td>
<td class="content">
It&#8217;s also possible to set a different email address for every project,
but we&#8217;re not covering that here.
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_step_3_create_an_empty_folder_and_1_file">Step 3: Create an empty folder and 1 file</h2>
<div class="sectionbody">
<div class="paragraph">
<p>In your terminal, create an empty folder and move into it.
Later on you could follow the same steps in this tutorial to take an
existing project and start managing it with Git, but we&#8217;re going to use
an empty project so that everyone following this tutorial has the exact
same files.</p>
</div>
<div class="paragraph">
<p>For example, run these commands to make a folder called <code>myproject</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ mkdir myproject
$ cd myproject</pre>
</div>
</div>
<div class="paragraph">
<p>Next, using your text editor, create a file in this folder, so we
have something to work with.</p>
</div>
<div class="paragraph">
<p>Make a file called README.md, with these contents:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>We're doing a Git tutorial!
We need 2 lines in this file so here's a second one</pre>
</div>
</div>
<div class="paragraph">
<p>Save <code>README.md</code> and keep it open in your text editor so you can
easily edit it later. The exact contents aren&#8217;t too important, but
we&#8217;ll use those contents in the example output later.</p>
</div>
<div class="paragraph">
<p>You can check that the file is in the right place by running <code>ls</code>,
like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ ls</pre>
</div>
</div>
<div class="paragraph">
<p>The output should look like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>README.md</pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_step_4_create_a_git_repository">Step 4: Create a Git repository</h2>
<div class="sectionbody">
<div class="paragraph">
<p>A Git repository lets you save snapshots of your code. Every time you make a
snapshot, Git stores a copy of the contents of every file in the snapshot.</p>
</div>
<div class="paragraph">
<p>This might feel unbelievable, but Git uses compression so you can easily
store tens of thousands of snapshots without using too much disk space.</p>
</div>
<div class="paragraph">
<p>You can create a Git repository for any folder in your computer by
running the command <code>git</code> <code>init</code>.</p>
</div>
<div class="paragraph">
<p>Run <code>git</code> <code>init</code> in the folder you just created, like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ git init</pre>
</div>
</div>
<div class="paragraph">
<p>Git will reply:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>Initialized empty Git repository in .git/</pre>
</div>
</div>
<div class="paragraph">
<p>You might notice a new hidden folder was created, named .<code>git</code>.
You don&#8217;t need to use this folder directly in any way, but it&#8217;s where
your commits will be stored.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_step_5_make_your_first_commit">Step 5: Make your first commit</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Next, we&#8217;re going to take a snapshot of all the files in the directory
and tell Git to store them. Git calls these snapshots "commits".
Making a commit in Git is a two step process: first you need to run <code>git</code>
<code>add</code> and then <code>git</code> <code>commit</code>.</p>
</div>
<div class="paragraph">
<p>The reason it&#8217;s a two step process is that sometimes you might not
actually want Git to store a commit with <em>all</em> the files in a folder.
For example, if you&#8217;re compiling your program to a binary, you might
want Git to put the program&#8217;s source code in your commit but not
compiled binary. You can also use a .<code>gitignore</code> file to help with this.</p>
</div>
<div class="paragraph">
<p>For now, we&#8217;re going to store a commit with every file in your folder,
as well as in every subfolder.</p>
</div>
<div class="paragraph">
<p>The first step of making a commit is to tell Git which files you
want to include in the commit using <code>git</code> <code>add</code>. To tell Git
"include all files", run this command:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ git add .</pre>
</div>
</div>
<div class="paragraph">
<p>To check if it succeeded, you can run <code>git</code> <code>status</code>.
The output should look like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ git status
On branch main
No commits yet
Changes to be committed:
(use "git rm --cached &lt;file&gt;..." to unstage)
new file: README.md</pre>
</div>
</div>
<div class="paragraph">
<p>Next you can create the commit using the <code>git</code> <code>commit</code> command, like
this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ git commit -m "Initial commit"</pre>
</div>
</div>
<div class="paragraph">
<p>The <code>-m</code> flag stands for "message", and it lets you set a reminder
for your future self of what you were doing. The message
("Initial commit" in this example) can say anything you want.</p>
</div>
<div class="paragraph">
<p>The output should look like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>[main (root-commit) 4a7e367] Initial commit
1 file changed, 2 insertions(+)
create mode 100644 README.md</pre>
</div>
</div>
<div class="paragraph">
<p>You&#8217;ve now stored the first version of your project in Git!</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_git_status_is_very_important"><code>git</code> <code>status</code> is very important</h2>
<div class="sectionbody">
<div class="paragraph">
<p><code>git</code> <code>status</code> shows you the current state of your Git repository.
It can give a huge amount of different information that takes
practice to interpret, so this tutorial has several examples of
how to interpret the output of <code>git</code> <code>status</code> in different situations.</p>
</div>
<div class="paragraph">
<p>It&#8217;s often useful to run <code>git</code> <code>status</code> before and after running a Git
command to see how it changed things.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_step_6_make_a_change">Step 6: Make a change</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Now, let&#8217;s learn how to make a change to a file and review the change you made.
In this example, we&#8217;ll update the file <code>README.md</code>, but you can edit a
different file.</p>
</div>
<div class="paragraph">
<p>First open <code>README.md</code> in your favourite text editor, make a tiny or
silly change, and save it. In our example, we&#8217;ll edit the first line to
add more exclamation marks:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>We're doing a Git tutorial!!!!</pre>
</div>
</div>
<div class="paragraph">
<p>Next, in the terminal, run the command <code>git</code> <code>status</code> to get a summary of
what you changed since the last Git commit.</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ git status</pre>
</div>
</div>
<div class="paragraph">
<p>The output will look something like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>On branch main
Changes not staged for commit:
(use "git add &lt;file&gt;..." to update what will be committed)
(use "git restore &lt;file&gt;..." to discard changes in working directory)
modified: README.md</pre>
</div>
</div>
<div class="paragraph">
<p>This output says that we&#8217;ve changed <code>README.md</code> since the last time
we committed.</p>
</div>
<div class="paragraph">
<p>Next, if you want to see the details of how you&#8217;ve changed <code>README.md</code>,
you can run <code>git</code> <code>diff</code>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ git diff</pre>
</div>
</div>
<div class="paragraph">
<p>The output will look something like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>diff --git a/README.md b/README.md
index ffa8b85..a49e4b0 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,2 @@
-We're doing a Git tutorial!
+We're doing a Git tutorial!!!!
We need 2 lines in this file so here's a second one</pre>
</div>
</div>
<div class="paragraph">
<p>This output says that we deleted one line (<code>We</code>'re <code>doing</code> <code>a</code> <code>Git</code>
<code>tutorial</code>!) and added one line (<code>We</code>'re <code>doing</code> <code>a</code> <code>Git</code> <code>tutorial</code>!!!!). By
default Git will show the lines you removed in red, and the lines you
added in green. Removed lines start with a minus <code>-</code> and added lines
start with a plus <code>+</code>.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_step_7a_make_a_second_commit">Step 7a: Make a second commit</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Now that we&#8217;ve changed <code>README.md</code>, let&#8217;s make another commit.
We&#8217;re going to follow the same steps as before when we made our first
commit.</p>
</div>
<div class="paragraph">
<p>First, tell Git that we want to include the new version of <code>README.md</code>
in the next commit:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ git add README.md</pre>
</div>
</div>
<div class="paragraph">
<p>and then run <code>git</code> <code>commit</code>, like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ git commit -m "Update README"</pre>
</div>
</div>
<div class="paragraph">
<p>The output should look like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>[main 32e0171] Update README
1 file changed, 1 insertion(+), 1 deletion(-)</pre>
</div>
</div>
<div class="paragraph">
<p>This says that the new commit is the same as the previous commit,
except that we changed 1 line of 1 file.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_step_7b_make_a_second_commit_the_short_way">Step 7b: Make a second commit (the short way)</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Instead of running the two commands in Step 7a above, you
could also run this command as a shortcut. It will:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Get a list of every file in the most recent commit</p>
</li>
<li>
<p>Commit the current version of all of those files</p>
</li>
</ol>
</div>
<div class="listingblock">
<div class="content">
<pre>$ git commit -am "Update README"</pre>
</div>
</div>
<div class="paragraph">
<p>The <code>-a</code> stands for "all".</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_understanding_git_status_output_untracked_files">Understanding <code>git</code> <code>status</code> output: "untracked files"</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Now let&#8217;s talk about a term you&#8217;ll see in the <code>git</code> <code>status</code> output:
"untracked files".</p>
</div>
<div class="paragraph">
<p>First create a new file called <code>example.txt</code>. It can be empty.</p>
</div>
<div class="paragraph">
<p>Then run the command <code>git</code> <code>status</code>. You should see this output:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>On branch main
Untracked files:
(use "git add &lt;file&gt;..." to include in what will be committed)
example.txt
nothing added to commit but untracked files present (use "git add" to track)</pre>
</div>
</div>
<div class="paragraph">
<p>This has a list of "untracked files". An untracked file is a file which
was not part of the latest commit. By default Git will ignore these
files.</p>
</div>
<div class="paragraph">
<p>If you want to commit an untracked file, you can add it like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ git add example.txt</pre>
</div>
</div>
<div class="paragraph">
<p>Then you can run <code>git</code> <code>commit</code> to commit it (though see the warning in
the next section!).</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_warning_about_terminal_text_editors">Warning about terminal text editors</h2>
<div class="sectionbody">
<div class="paragraph">
<p>If you run <code>git</code> <code>commit</code> without any arguments, Git will open a
text editor in the terminal for you to use to edit your commit message.
This lets you write a longer commit message with more details.
By default, Git uses the <code>vi</code> text editor, which is extremely difficult
to use if you&#8217;re not used to it. On Windows, the Git installer asks you
to set your text editor during the install to avoid this problem.</p>
</div>
<div class="paragraph">
<p>Some signs that you&#8217;re trapped in <code>vi</code>: suddenly typing doesn&#8217;t work
anymore, and there are tilde <code>~</code> characters on the bottom left of the
screen.</p>
</div>
<div class="paragraph">
<p>If Git opens <code>vi</code> and you&#8217;d rather use a different editor, you can
handle it like this:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Quit by pressing the <code>Escape</code> key, then typing <code>:q</code>! and then <code>Enter</code></p>
</li>
<li>
<p>Run <code>git</code> <code>config</code> <code>--global</code> <code>core.editor</code> <code>YOUR_PREFERRED_EDITOR</code>
to configure which editor to use. For example, <code>nano</code> is available
on a lot of systems and has basic instructions on the screen for how
to use it. Here is a list of
<a href="https://git-scm.com/book/en/v2/Appendix-C:-Git-Commands-Setup-and-Config#ch_core_editor">how to configure some common editors</a>.</p>
</li>
<li>
<p>Run <code>git</code> <code>commit</code> again</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>If you don&#8217;t want to set up a text editor yet, you can also just use
<code>git</code> <code>commit</code> <code>-m</code>"your <code>message</code>" like we did earlier in this tutorial.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_step_8_make_a_change_and_throw_it_away">Step 8: Make a change and throw it away</h2>
<div class="sectionbody">
<div class="paragraph">
<p>One of the most useful things about Git is that it lets you safely
experiment: you never need to be scared to change your code because you
can always go back to the old version.</p>
</div>
<div class="paragraph">
<p>Before starting to experiment, run <code>git</code> <code>status</code> to check the current
state of your Git repository:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ git status
On branch main
nothing to commit, working tree clean</pre>
</div>
</div>
<div class="paragraph">
<p>This "working tree clean" message means that there haven&#8217;t been any
changes since your last commit.</p>
</div>
<div class="paragraph">
<p>Now make a change to <code>README.md</code>, and run <code>git</code> <code>status</code> again. Like last
time, you should see a message like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ git status
On branch main
Changes not staged for commit:
(use "git add &lt;file&gt;..." to update what will be committed)
(use "git restore &lt;file&gt;..." to discard changes in working directory)
modified: README.md</pre>
</div>
</div>
<div class="paragraph">
<p>This tells us that <code>README.md</code> has been changed since the last commit.
But we don&#8217;t actually want this change, so let&#8217;s undo it! We can restore
<code>README.md</code> back to how it was at the most recent commit using the <code>git</code>
<code>restore</code> command.</p>
</div>
<div class="paragraph">
<p><strong>WARNING</strong>: <code>git</code> <code>restore</code> can&#8217;t be reversed! Any time you run it it&#8217;s
important to be absolutely sure that you&#8217;re okay with throwing away your
changes since the last commit.</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ git restore README.md</pre>
</div>
</div>
<div class="paragraph">
<p>Now open <code>README.md</code> again. You should see that your changes have been undone.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_you_can_stop_here">You can stop here!</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The commands we&#8217;ve learned so far (<code>git</code> <code>init</code>, <code>git</code> <code>add</code>, <code>git</code> <code>commit</code>,
<code>git</code> <code>diff</code>, <code>git</code> <code>status</code>, and <code>git</code> <code>restore</code>) are enough to get a lot out
of Git on their own.</p>
</div>
<div class="paragraph">
<p>With these commands, you can keep copies of past versions of your code
on your computer and safely experiment with big changes to your code.</p>
</div>
<div class="paragraph">
<p>When using Git this way, all of your code just lives on your computer.
But if you want to put your code on the Internet so that other people
can use it or back it up, then you&#8217;ll need to learn about one more
command: <code>git</code> <code>push</code>.</p>
</div>
<div class="paragraph">
<p>The rest of this tutorial is about how to upload your code to a Git
repository on the Internet. The high level process is:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Create an account on the Git host</p>
</li>
<li>
<p>Configure Git so that it can login to the Git host to make changes</p>
</li>
<li>
<p>Run <code>git</code> <code>push</code> <code>origin</code> <code>main</code> to upload your code</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>Navigating the Git host&#8217;s UI can be tricky, and it&#8217;s hard for us to
give you exact directions because the UIs change a lot.
There&#8217;s a rich tradition of people learning Git from their "Git friend"
who already knows Git, and if you have one of those it might be useful
to ask them if you get stuck. There are many ways to do things in Git,
so they might suggest a slightly different way.
There&#8217;s also a troubleshooting guide at the end with the most common
issues folks have run into while doing this tutorial.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_step_9_create_an_account_on_a_git_host">Step 9: Create an account on a Git host</h2>
<div class="sectionbody">
<div class="paragraph">
<p>To put your code on the Internet, you need it to be hosted somewhere.
The easiest way to do this is to sign up with a Git host. There&#8217;s a list
of Git hosts (many of them offer free accounts) at
<a href="https://git-scm.com/tools/hosting" class="bare">https://git-scm.com/tools/hosting</a>. GitHub and GitLab are two popular hosts.</p>
</div>
<div class="paragraph">
<p>If you&#8217;re comfortable running a server, there are other ways to host
a Git repository on the internet, like connecting through SSH or open
source Git forge software to your server.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_step_10_maclinux_only_create_an_ssh_key_if_needed">Step 10 (Mac/Linux only): Create an SSH key if needed</h2>
<div class="sectionbody">
<div class="paragraph">
<p>For Git to upload changes to another Git repository, it needs a way to
login to that repository. One of the most popular ways to do this is
with an SSH key.</p>
</div>
<div class="paragraph">
<p>On Windows, you can skip this step and the next one because Git for
Windows comes with
<a href="https://github.com/git-ecosystem/git-credential-manager">Git Credential Manager</a>
to handle logging in.</p>
</div>
<div class="paragraph">
<p>If you don&#8217;t already have an SSH key, you&#8217;ll need to create one.
You can check if you already have an SSH key by running:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ ls ~/.ssh/*.pub</pre>
</div>
</div>
<div class="paragraph">
<p>If you don&#8217;t already have an SSH key, run:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ ssh-keygen</pre>
</div>
</div>
<div class="paragraph">
<p><code>ssh-keygen</code> will ask you for some details.
The easiest way to do this is to just press Enter at every prompt until
it&#8217;s done.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<div class="title">Note</div>
</td>
<td class="content">
All of the advice about how to use SSH in this tutorial is aimed
at getting it to work as quickly as possible. Setting up SSH in a secure
way is very far outside the scope of this tutorial. If you have a
security team in your organization, they might have very different
opinions about the appropriate way to configure authentication with Git.
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_step_11_maclinux_only_tell_the_git_host_your_ssh_public_key">Step 11 (Mac/Linux only): Tell the Git host your SSH public key</h2>
<div class="sectionbody">
<div class="paragraph">
<p>First, find your SSH key like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ ls ~/.ssh/*.pub</pre>
</div>
</div>
<div class="paragraph">
<p>That will output something like this. The exact filename depends on the type
of key. The important thing is that you&#8217;re looking for a filename that
ends in .<code>pub</code> ("pub" stands for "public"):</p>
</div>
<div class="listingblock">
<div class="content">
<pre>/home/alice/.ssh/id_ed25519.pub</pre>
</div>
</div>
<div class="paragraph">
<p>Copy the contents of that file to your clipboard. One way to do that is
to run this command (replacing the filename with the right filename),
and then copy the output.</p>
</div>
<div class="listingblock">
<div class="content">
<pre>cat /home/alice/.ssh/id_ed25519.pub</pre>
</div>
</div>
<div class="paragraph">
<p>Then login to your account on the Git host you chose and paste the SSH
key into the appropriate place. Depending on the Git host, it&#8217;s likely
under "SSH keys" in your settings. If it asks you what type of SSH key,
look for something like "Authentication Key".</p>
</div>
<div class="paragraph">
<p>Once you&#8217;ve done this, you&#8217;re done! Git will automatically use your SSH
key to try to connect.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="step_12">Step 12: Create an empty Git repository on the Git host</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Go to the Git host&#8217;s website and create a new Git repository. If there&#8217;s
an option to "create a README.md", "add a license", or something
similar, make sure to say no to all of them.</p>
</div>
<div class="paragraph">
<p><strong>WARNING</strong>: If you create a public repository and push your repository
to it, then your name and email address, as well as the contents of
any files you committed and every previous version of those files, will
be on the public internet. Some Git hosts have the option to create
a private repository instead, to keep your information private.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_step_13_find_the_address_of_the_repository">Step 13: Find the address of the repository</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Now, find the address of the repository on your Git host.</p>
</div>
<div class="paragraph">
<p>If you followed the Mac/Linux instructions to set up an SSH key, look
for an "SSH" address like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>git@git.example.com:username/repo.git</pre>
</div>
</div>
<div class="paragraph">
<p>If you&#8217;re on Windows, look for an "HTTPS" address like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>https://git.example.com/username/repo.git</pre>
</div>
</div>
<div class="paragraph">
<p>(where <code>example.com</code>, <code>username</code> and <code>repo</code> will be replaced with the
actual values).</p>
</div>
<div class="paragraph">
<p>If you can only find an address starting with <code>https://</code> and you need
an SSH address then you can often translate it to the SSH format by
replacing <code>https://</code> with <code>git@</code> and replacing the <code>/</code> after the domain
name with an <code>:</code>. Here&#8217;s how:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>https://git.example.com/username/repo
^^^^^^^^ ^
replace with "git@" replace with ":"</pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="step_14">Step 14: Push your changes</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Finally, we&#8217;re ready to send the information in your local Git repository
to the one on the internet!</p>
</div>
<div class="paragraph">
<p>First, tell Git about the other repository by running <code>git</code> <code>remote</code> <code>add</code>
in your terminal
(replace <code>git@example.com:username/repo.git</code> with the address from Step 13):</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ git remote add origin git@example.com:username/repo.git</pre>
</div>
</div>
<div class="paragraph">
<p>This tells Git to save the URL <code>git@example.com:username/repo.git</code> in
your Git repository&#8217;s configuration under the name <code>origin</code>, so that you
can use it later. If you make a mistake while doing this, you can run
<code>git</code> <code>remote</code> <code>remove</code> <code>origin</code> and try again.</p>
</div>
<div class="paragraph">
<p>Then tell Git to send the information, with <code>git</code> <code>push</code>
(if this doesn&#8217;t work, read the "Troubleshooting <code>git</code> <code>push</code>" section for advice!):</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ git push --set-upstream origin main</pre>
</div>
</div>
<div class="paragraph">
<p>On Windows, this should pop up a dialog from Git Credential Manager
asking you to log in to the Git host in your browser.</p>
</div>
<div class="paragraph">
<p>Let&#8217;s break down this <code>git</code> <code>push</code> command:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>origin</code> refers to the Git repository that we just added with
<code>git</code> <code>remote</code> <code>add</code> (<code>git@example.com:username/repo.git</code>).
You can use any name (not just <code>origin</code>), but using <code>origin</code> often
makes things easier because it&#8217;s the default for <code>git</code> <code>push</code> and <code>git</code> <code>pull</code>.</p>
</li>
<li>
<p><code>main</code> is the name of your current Git branch.
We haven&#8217;t covered branches yet, but <code>main</code> is the default branch name.</p>
</li>
<li>
<p><code>--set-upstream</code> tells Git to make this the default for <code>git</code> <code>push</code> for
the <code>main</code> branch. After you set the upstream, <code>git</code> <code>status</code> will
also tell you if you have commits that haven&#8217;t been pushed.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>The output should look like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 8 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (7/7), 662 bytes | 662.00 KiB/s, done.
Total 7 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
To example.com:username/repo
* [new branch] main -&gt; main
branch 'main' set up to track 'origin/main'.</pre>
</div>
</div>
<div class="paragraph">
<p>Any time you want to set up a new repository, you can repeat steps
12-14, with one exception: you only need to pass <code>--set-upstream</code> the first time
you push. Afterwards you can just run the command:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ git push origin main</pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_troubleshooting_git_push">Troubleshooting <code>git</code> <code>push</code></h2>
<div class="sectionbody">
<div class="paragraph">
<p>There are 3 main errors you might run into when running <code>git</code> <code>push</code> <code>origin</code> <code>main</code>.
Getting errors when running <code>git</code> <code>push</code> is actually a big part of using
Git, so congratulations! If you get to this part of the tutorial, you
get a little bonus experience in debugging.</p>
</div>
<div class="paragraph">
<p>Here&#8217;s a guide to why they&#8217;re happening and how to fix them.</p>
</div>
<div class="paragraph">
<p><strong>Problem 1: You pushed to <code>main</code>, but your branch actually isn&#8217;t called <code>main</code></strong></p>
</div>
<div class="paragraph">
<p>Here&#8217;s the error:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ git push origin main
error: src refspec main does not match any</pre>
</div>
</div>
<div class="paragraph">
<p>This might happen if you didn&#8217;t set <code>init.defaultBranch</code> to <code>main</code> in
<a href="#step_2">Step 2</a>.</p>
</div>
<div class="paragraph">
<p>If you want to check the name of your current branch, you can run <code>git</code>
<code>status</code>. For example, in this output, the current branch is "master".</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ git status
On branch master
...</pre>
</div>
</div>
<div class="paragraph">
<p>To push your branch, you have a few options:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>rename your branch to <code>main</code>, by running <code>git</code> <code>branch</code> <code>-m</code> <code>main</code>
and then run <code>git</code> <code>push</code> <code>origin</code> <code>main</code></p>
</li>
<li>
<p>run <code>git</code> <code>push</code> <code>origin</code> <code>master</code>
(where <code>master</code> is the name of your actual current branch)</p>
</li>
</ul>
</div>
<div class="paragraph">
<p><strong>Problem 2: SSH error</strong></p>
</div>
<div class="paragraph">
<p>Here&#8217;s the error:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ git push origin main
The authenticity of host 'github.com (140.82.116.3)' can't be established.
ED25519 key fingerprint is: SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])?</pre>
</div>
</div>
<div class="paragraph">
<p>Git uses SSH to connect during <code>git</code> <code>push</code>, and this message happens when
SSH connects to a new site that you haven&#8217;t connected to before.</p>
</div>
<div class="paragraph">
<p>The easiest way to handle this is to type "yes" and press Enter.</p>
</div>
<div class="paragraph">
<p><strong>Problem 3: the repository already has commits in it</strong></p>
</div>
<div class="paragraph">
<p>Here&#8217;s the error:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ git push origin main
! [rejected] main -&gt; main (fetch first)
error: failed to push some refs to 'example.com:username/repo.git'
hint: Updates were rejected because the remote contains work that you do not
hint: have locally.</pre>
</div>
</div>
<div class="paragraph">
<p>If you see an error like this, it means that when you created the
repository on your Git host, it added a commit to try to help you out.
That&#8217;s the "work that you do not have locally" in the error message.</p>
</div>
<div class="paragraph">
<p>You should be able to fix this by redoing <a href="#step_12">Step 12</a>.
Then <a href="#step_14">Step 14</a> should work.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_more_useful_git_commands">More useful Git commands</h2>
<div class="sectionbody">
<div class="paragraph">
<p>We&#8217;re not going to cover collaboration at all in this tutorial, but here are a
few more commands that might be useful when using Git on your own:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>To download a Git repository to use on your computer you can run
<code>git</code> <code>clone</code> <code>https://example.com/some/repo</code> (<a href="git-clone.html">git-clone(1)</a>).</p>
</li>
<li>
<p>To tell Git to "un-add" a file that you added by accident, run
<code>git</code> <code>rm</code> <code>--cached</code> <code>FILENAME</code> (<a href="git-rm.html">git-rm(1)</a>)</p>
</li>
<li>
<p>To get a list of past commits, run <code>git</code> <code>log</code> (<a href="git-log.html">git-log(1)</a>)</p>
</li>
<li>
<p>Every commit has an ID that looks something like this:
<code>497588f53141b531a59ed888c7d2d9b8f8a6742d</code>.
If you see a commit with <code>git</code> <code>log</code> that you want more details about,
you can run <code>git</code> <code>show</code> <code>COMMIT_ID</code> to see what changes that made since
the previous commit (<a href="git-show.html">git-show(1)</a>)</p>
</li>
<li>
<p>To get a list of common Git commands, run <code>git</code> <code>help</code> (<a href="git-help.html">git-help(1)</a>)</p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_git">GIT</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Part of the <a href="git.html">git(1)</a> suite</p>
</div>
</div>
</div>
</div>
<div id="footer">
<div id="footer-text">
Last updated 2026-11-09 19:51:07 -0800
</div>
</div>
</body>
</html>