|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="utf-8"> |
| 5 | + <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> |
| 6 | + <title>git - the simple guide - no deep shit!</title> |
| 7 | + <link href='http://fonts.googleapis.com/css?family=Chelsea+Market' rel='stylesheet' type='text/css'> |
| 8 | + <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/normalize/0/normalize.min.css" type="text/css"> |
| 9 | + <link rel="stylesheet" href="css/style.css" type="text/css"> |
| 10 | + |
| 11 | +</head> |
| 12 | +<body> |
| 13 | + <div class="scrollblock block-title"> |
| 14 | + <h1>git - the simple guide</h1> |
| 15 | + <p>just a simple guide for getting started with git. no deep shit ;)</p> |
| 16 | + <a href="https://twitter.com/share" class="twitter-share-button" data-via="rogerdudler" data-size="large" data-url="http://rogerdudler.github.com/git-guide" data-related="rogerdudler" data-hashtags="git">Tweet</a> |
| 17 | + <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script> |
| 18 | + <p class="meta"> |
| 19 | + by <a href="http://www.twitter.com/rogerdudler">Roger Dudler</a> |
| 20 | + <br />credits to <a href="http://www.twitter.com/tfnico">@tfnico</a>, <a href="http://www.twitter.com/fhd">@fhd</a> and <a href="http://www.namics.com">Namics</a><br /> |
| 21 | + this guide in |
| 22 | + <a href="index.en.html">english</a>, |
| 23 | + <a href="index.de.html">deutsch</a>, |
| 24 | + <a href="index.es.html">español</a>, |
| 25 | + <a href="index.fr.html">français</a>, |
| 26 | + <a href="index.id.html">indonesian</a>, |
| 27 | + <a href="index.it.html">italiano</a>, |
| 28 | + <a href="index.pl.html">polski</a>, |
| 29 | + <a href="index.pt_BR.html">português</a>, |
| 30 | + <a href="index.ru.html">русский</a>, |
| 31 | + <a href="index.tr.html">türkçe</a>, |
| 32 | + <br/> |
| 33 | + <a href="index.my.html">မြန်မာ</a>, |
| 34 | + <a href="index.ja.html">日本語</a>, |
| 35 | + <a href="index.zh.html">中文</a>, |
| 36 | + <a href="index.ko.html">한국어</a>, |
| 37 | + <a href="index.vi.html">Vietnamese</a>, |
| 38 | + <a href="index.html">فارسی</a> |
| 39 | + <br /> |
| 40 | + please report issues on <a href="https://github.com/rogerdudler/git-guide/issues">github</a> |
| 41 | + </p> |
| 42 | + <script async type="text/javascript" src="//cdn.carbonads.com/carbon.js?zoneid=1673&serve=C6AILKT&placement=gitguide" id="_carbonads_js"></script> |
| 43 | + <img src="img/arrow.png" alt="" /> |
| 44 | + </div> |
| 45 | + <!-- setup --> |
| 46 | + <a name="setup"></a> |
| 47 | + <div class="scrollblock block-setup"> |
| 48 | + <h2>setup</h2> |
| 49 | + <p> |
| 50 | + <a href="http://git-scm.com/download/mac">Download git for OSX</a> |
| 51 | + </p> |
| 52 | + <p> |
| 53 | + <a href="https://git-scm.com/download/win">Download git for Windows</a> |
| 54 | + </p> |
| 55 | + <p> |
| 56 | + <a href="https://git-scm.com/download/linux">Download git for Linux</a> |
| 57 | + </p> |
| 58 | + </div> |
| 59 | + <a name="create"></a> |
| 60 | + <div class="scrollblock block-create"> |
| 61 | + <h2>create a new repository</h2> |
| 62 | + <p> |
| 63 | + create a new directory, open it and perform a <br /> |
| 64 | + <code>git init</code><br /> |
| 65 | + to create a new git repository. |
| 66 | + </p> |
| 67 | + </div> |
| 68 | + <a name="checkout"></a> |
| 69 | + <div class="scrollblock block-checkout"> |
| 70 | + <h2>checkout a repository</h2> |
| 71 | + <p> |
| 72 | + create a working copy of a local repository by running the command<br /> |
| 73 | + <code>git clone /path/to/repository</code><br /> |
| 74 | + when using a remote server, your command will be<br /> |
| 75 | + <code>git clone username@host:/path/to/repository</code> |
| 76 | + </p> |
| 77 | + </div> |
| 78 | + <a name="trees"></a> |
| 79 | + <div class="scrollblock block-trees"> |
| 80 | + <h2>workflow</h2> |
| 81 | + <p> |
| 82 | + your local repository consists of three "trees" maintained by git. |
| 83 | + the first one is your <code>Working Directory</code> which holds the actual files. |
| 84 | + the second one is the <code>Index</code> which acts as a staging area and |
| 85 | + finally the <code>HEAD</code> which points to the last commit you've made. |
| 86 | + </p> |
| 87 | + <img src="img/trees.png" alt="" /> |
| 88 | + </div> |
| 89 | + <a name="add"></a> |
| 90 | + <div class="scrollblock block-add"> |
| 91 | + <h2>add & commit</h2> |
| 92 | + <p> |
| 93 | + You can propose changes (add it to the <b>Index</b>) using<br /> |
| 94 | + <code>git add <filename></code><br /> |
| 95 | + <code>git add *</code><br /> |
| 96 | + This is the first step in the basic git workflow. To actually commit these changes use<br /> |
| 97 | + <code>git commit -m "Commit message"</code><br /> |
| 98 | + Now the file is committed to the <b>HEAD</b>, but not in your remote repository yet. |
| 99 | + </p> |
| 100 | + </div> |
| 101 | + <a name="push"></a> |
| 102 | + <div class="scrollblock block-remote"> |
| 103 | + <h2>pushing changes</h2> |
| 104 | + <p> |
| 105 | + Your changes are now in the <b>HEAD</b> of your local working copy. To send those changes to your remote repository, execute <br /> |
| 106 | + <code>git push origin master</code><br /> |
| 107 | + Change <i>master</i> to whatever branch you want to push your changes to. |
| 108 | + <br /><br /> |
| 109 | + If you have not cloned an existing repository and want to connect your repository to a remote server, you need to add it with<br /> |
| 110 | + <code>git remote add origin <server></code><br /> |
| 111 | + Now you are able to push your changes to the selected remote server<br /> |
| 112 | + |
| 113 | + </p> |
| 114 | + </div> |
| 115 | + <a name="branching"></a> |
| 116 | + <div class="scrollblock block-branching"> |
| 117 | + <h2>branching</h2> |
| 118 | + <p> |
| 119 | + Branches are used to develop features isolated from each other. The <i>master</i> branch is the "default" branch when you create a repository. Use other branches for development and merge them back to the master branch upon completion. |
| 120 | + </p> |
| 121 | + <img src="img/branches.png" alt="" /> |
| 122 | + <p> |
| 123 | + create a new branch named "feature_x" and switch to it using<br /> |
| 124 | + <code>git checkout -b feature_x</code><br /> |
| 125 | + switch back to master<br /> |
| 126 | + <code>git checkout master</code><br /> |
| 127 | + and delete the branch again<br /> |
| 128 | + <code>git branch -d feature_x</code><br /> |
| 129 | + a branch is <i>not available to others</i> unless you push the branch to your remote repository<br /> |
| 130 | + <code>git push origin <branch></code> |
| 131 | + </p> |
| 132 | + </div> |
| 133 | + <a name="update"></a> |
| 134 | + <div class="scrollblock block-merging"> |
| 135 | + <h2>update & merge</h2> |
| 136 | + <p> |
| 137 | + to update your local repository to the newest commit, execute <br /> |
| 138 | + <code>git pull</code><br /> |
| 139 | + in your working directory to <i>fetch</i> and <i>merge</i> remote changes.<br /> |
| 140 | + to merge another branch into your active branch (e.g. master), use<br /> |
| 141 | + <code>git merge <branch></code><br /> |
| 142 | + in both cases git tries to auto-merge changes. Unfortunately, this is not always possible and results in <i>conflicts</i>. |
| 143 | + You are responsible to merge those <i>conflicts</i> |
| 144 | + manually by editing the files shown by git. After changing, you need to mark them as merged with<br /> |
| 145 | + <code>git add <filename></code><br /> |
| 146 | + before merging changes, you can also preview them by using<br /> |
| 147 | + <code>git diff <source_branch> <target_branch></code> |
| 148 | + </p> |
| 149 | + </div> |
| 150 | + <a name="tagging"></a> |
| 151 | + <div class="scrollblock block-tagging"> |
| 152 | + <h2>tagging</h2> |
| 153 | + <p> |
| 154 | + it's recommended to create tags for software releases. this is a known concept, which also exists in SVN. You can create a new tag named <i>1.0.0</i> by executing<br /> |
| 155 | + <code>git tag 1.0.0 1b2e1d63ff</code><br /> |
| 156 | + the <i>1b2e1d63ff</i> stands for the first 10 characters of the commit id you want to reference with your tag. You can get the commit id by looking at the... <br /> |
| 157 | + </p> |
| 158 | + </div> |
| 159 | + <a name="log"></a> |
| 160 | + <div class="scrollblock block-log"> |
| 161 | + <h2>log</h2> |
| 162 | + <p> |
| 163 | + in its simplest form, you can study repository history using.. |
| 164 | + <code>git log</code><br /> |
| 165 | + You can add a lot of parameters to make the log look like what you want. To see only the commits of a certain author:<br /> |
| 166 | + <code>git log --author=bob</code><br /> |
| 167 | + To see a very compressed log where each commit is one line:<br /> |
| 168 | + <code>git log --pretty=oneline</code><br /> |
| 169 | + Or maybe you want to see an ASCII art tree of all the branches, decorated with the names of tags and branches: <br /> |
| 170 | + <code>git log --graph --oneline --decorate --all</code><br /> |
| 171 | + See only which files have changed: <br /> |
| 172 | + <code>git log --name-status</code><br /> |
| 173 | + These are just a few of the possible parameters you can use. For more, see |
| 174 | + <code>git log --help</code><br /> |
| 175 | + </p> |
| 176 | + </div> |
| 177 | + <a name="checkout-replace"></a> |
| 178 | + <div class="scrollblock block-checkout-replace"> |
| 179 | + <h2>replace local changes</h2> |
| 180 | + <p> |
| 181 | + In case you did something wrong, which for sure never happens ;), you can replace local changes using the command<br /> |
| 182 | + <code>git checkout -- <filename></code><br /> |
| 183 | + this replaces the changes in your working tree with the last content in HEAD. Changes already added to the index, as well as new files, will be kept. |
| 184 | + </p> |
| 185 | + <p> |
| 186 | + If you instead want to drop all your local changes and commits, fetch the latest history from the server and point your local master branch at it like this<br /> |
| 187 | + <code>git fetch origin</code><br /> |
| 188 | + <code>git reset --hard origin/master</code> |
| 189 | + </p> |
| 190 | + </div> |
| 191 | + <a name="hints"></a> |
| 192 | + <div class="scrollblock block-hints"> |
| 193 | + <h2>useful hints</h2> |
| 194 | + <p> |
| 195 | + built-in git GUI<br /> |
| 196 | + <code>gitk</code><br /> |
| 197 | + use colorful git output<br /> |
| 198 | + <code>git config color.ui true</code><br /> |
| 199 | + show log on just one line per commit<br /> |
| 200 | + <code>git config format.pretty oneline</code><br /> |
| 201 | + use interactive adding<br /> |
| 202 | + <code>git add -i</code> |
| 203 | + </p> |
| 204 | + </div> |
| 205 | + <a name="resources"></a> |
| 206 | + <div class="scrollblock block-resources"> |
| 207 | + <h2>links & resources</h2> |
| 208 | + <h3>graphical clients</h3> |
| 209 | + <p> |
| 210 | + <ul> |
| 211 | + <li><a href="http://gitx.laullon.com/">GitX (L) (OSX, open source)</a></li> |
| 212 | + <li><a href="http://www.git-tower.com/">Tower (OSX)</a></li> |
| 213 | + <li><a href="http://www.sourcetreeapp.com/">Source Tree (OSX & Windows, free)</a></li> |
| 214 | + <li><a href="http://mac.github.com/">GitHub for Mac (OSX, free)</a></li> |
| 215 | + <li><a href="https://itunes.apple.com/gb/app/gitbox/id403388357?mt=12">GitBox (OSX, App Store)</a></li> |
| 216 | + </ul> |
| 217 | + </p> |
| 218 | + <h3>guides</h3> |
| 219 | + <p> |
| 220 | + <ul> |
| 221 | + <li><a href="http://book.git-scm.com/">Git Community Book</a></li> |
| 222 | + <li><a href="http://progit.org/book/">Pro Git</a></li> |
| 223 | + <li><a href="http://think-like-a-git.net/">Think like a git</a></li> |
| 224 | + <li><a href="http://help.github.com/">GitHub Help</a></li> |
| 225 | + <li><a href="http://marklodato.github.com/visual-git-guide/index-en.html">A Visual Git Guide</a></li> |
| 226 | + </ul> |
| 227 | + </p> |
| 228 | + <h3>get help</h3> |
| 229 | + <p> |
| 230 | + <ul> |
| 231 | + <li><a href="http://groups.google.com/group/git-users/">Git User Mailing List</a></li> |
| 232 | + <li><a href="http://jk.gs/git/">#git on irc.freenode.net</a></li> |
| 233 | + </ul> |
| 234 | + </p> |
| 235 | + </div> |
| 236 | + <a href="files/git_cheat_sheet.pdf" onClick="recordOutboundLink(this, 'Cheat Sheet', 'git-guide');return false;" class="cheatsheet"></a> |
| 237 | +</body> |
| 238 | +</html> |
0 commit comments