git
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| git [2026/07/08 22:14] – [checkout] jhagstrand | git [2026/08/06 07:54] (current) – [repository] jhagstrand | ||
|---|---|---|---|
| Line 52: | Line 52: | ||
| === bare=== | === bare=== | ||
| a bare repository is a folder named project.git\\ | a bare repository is a folder named project.git\\ | ||
| - | a non-bare repository is a subfolder | + | a non-bare repository is a sub-folder |
| - | git init | + | git init # executed from within a new project folder, creates the .git folder |
| - | git clone | + | git init --bare flash.git |
| + | | ||
| + | git clone < | ||
| ====remote==== | ====remote==== | ||
| Line 273: | Line 275: | ||
| This allows developers to work on multiple ideas at once, and switch back and forth. | This allows developers to work on multiple ideas at once, and switch back and forth. | ||
| - | === git checkout < | + | **git checkout < |
| When you change your mind about the changes you've made, restore the file back to where it was before you started. | When you change your mind about the changes you've made, restore the file back to where it was before you started. | ||
| - | === git checkout < | + | **git checkout < |
| When I'm testing my app and I'm not sure if my latest commit was successful, | When I'm testing my app and I'm not sure if my latest commit was successful, | ||
| I can temporarily switch back to the previous commit and test that to refresh my memory. | I can temporarily switch back to the previous commit and test that to refresh my memory. | ||
| Line 285: | Line 286: | ||
| Anytime the HEAD is pointed at a commit other than the one at the top of the current branch, it is considered detached. | Anytime the HEAD is pointed at a commit other than the one at the top of the current branch, it is considered detached. | ||
| Repeat the git checkout < | Repeat the git checkout < | ||
| + | |||
| + | ==== checkout ==== | ||
| + | |||
| + | The repo is a library of commits. | ||
| + | At any time, you can checkout a whole commit or a specific file within that commit. | ||
| + | |||
| + | A branch is a pointer to a commit. | ||
| + | The HEAD is also a pointer to a commit. | ||
| + | |||
| + | When the HEAD points to a commit that is not also the top of a branch, the HEAD is considered " | ||
| + | |||
| + | The checkout command does two things: | ||
| + | 1. Points the HEAD to the specified commit. | ||
| + | 2. Brings the working tree into line with the new HEAD commit. | ||
| + | |||
| + | You can specify a commit, a branch, or a file. | ||
| + | |||
| + | git checkout < | ||
| + | git checkout < | ||
| + | git checkout < | ||
| + | |||
| + | You can specify a branch or a commit; either way you are specifying a commit. | ||
| + | If you specify a file, there is no need to move the HEAD. It just modifies that one file in the working tree to bring it into line with the current commit. | ||
| + | |||
| + | Younger developers who don't yet fully understand the checkout command, in 2019, introduced two new aliases. | ||
| + | |||
| + | ^ correct | ||
| + | | git checkout < | ||
| + | | git checkout < | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| ====diff==== | ====diff==== | ||
| Line 296: | Line 331: | ||
| By default diff compares all of the currently modified files. | By default diff compares all of the currently modified files. | ||
| - | git diff | + | git diff |
| - | git add . | + | git add . # staging |
| - | git diff HEAD # after the add | + | git diff HEAD # after staging |
| + | git diff --staged | ||
| Additional options. | Additional options. | ||
| Line 350: | Line 386: | ||
| https:// | https:// | ||
| + | |||
| + | ==== Combinations ==== | ||
| + | |||
| + | Some git command options effectively execute multiple git commands simultaneously. | ||
| + | Here are some examples. | ||
| + | |||
| + | 1. git add . | ||
| + | 2. git commit -m ' | ||
| + | 1+2. git -a commit -m ' | ||
| + | |||
| + | 1. git clone < | ||
| + | 2. git submodule init | ||
| + | 3. git submodule update | ||
| + | 2+3. git submodule update --init | ||
| + | 1+2+3. git clone --recursive-submodules < | ||
| + | |||
| + | 1. git fetch # download patch files | ||
| + | 2. git merge # apply patches to local files | ||
| + | 1+2. git pull # fetch and merge | ||
| + | |||
| + | ====Fork==== | ||
| + | In github ui, fork repo from voyc to hagstrand. | ||
| + | |||
| + | Locally: | ||
| + | git clone xttps:// | ||
| + | git remote add upstream xttps: | ||
| + | git pull --rebase upstream master | ||
| + | # pull does a fetch and merge into local directory. | ||
| + | git push origin master | ||
| + | Todo: Rename? | ||
| + | Todo: In github UI, “Pull Request” to bring forked project back into upstream. | ||
| + | |||
| + | |||
| ===== How to use ===== | ===== How to use ===== | ||
| Line 631: | Line 700: | ||
| git submodule update --init | git submodule update --init | ||
| - | ==== Combinations ==== | ||
| - | |||
| - | Some git command options effectively execute multiple git commands simultaneously. | ||
| - | Here are some examples. | ||
| - | |||
| - | 1. git add . | ||
| - | 2. git commit -m ' | ||
| - | 1+2. git -a commit -m ' | ||
| - | |||
| - | 1. git clone < | ||
| - | 2. git submodule init | ||
| - | 3. git submodule update | ||
| - | 2+3. git submodule update --init | ||
| - | 1+2+3. git clone --recursive-submodules < | ||
| - | |||
| - | 1. git fetch # download patch files | ||
| - | 2. git merge # apply patches to local files | ||
| - | 1+2. git pull # fetch and merge | ||
| - | |||
| - | ====Fork==== | ||
| - | In github ui, fork repo from voyc to hagstrand. | ||
| - | |||
| - | Locally: | ||
| - | git clone xttps:// | ||
| - | git remote add upstream xttps: | ||
| - | git pull --rebase upstream master | ||
| - | # pull does a fetch and merge into local directory. | ||
| - | git push origin master | ||
| - | Todo: Rename? | ||
| - | Todo: In github UI, “Pull Request” to bring forked project back into upstream. | ||
| - | ====See the current changes==== | ||
| - | git diff # before staging (git add *) | ||
| - | git diff --staged # after staging | ||
| ==== Remove a submodule ==== | ==== Remove a submodule ==== | ||
git.1783563283.txt.gz · Last modified: 2026/07/08 22:14 by jhagstrand