User Tools

Site Tools


git

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
git [2026/06/16 00:13] – [diff] jhagstrandgit [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 named .git, co-residing in the project folder along with the working copy\\+a non-bare repository is a sub-folder named .git, co-residing in the project folder along with the working copy\\
  
-  git init +  git init  # executed from within a new project folder, creates the .git folder 
-  git clone+  git init --bare flash.git  # create a new sub-folder named flash.git   
 +   
 +  git clone <server.path>.flash.git # create sub-folder named flash, within which lies the .git sub-folder
  
 ====remote==== ====remote====
Line 268: Line 270:
 | git checkout <commit>  | (none)   | | git checkout <commit>  | (none)   |
  
-The old checkout commands still work as always.  And kudos to the git developers for honoring backward compatibility.+The old checkout command still works the same as always
 + 
 +**git checkout <branch>** 
 +This allows developers to work on multiple ideas at once, and switch back and forth. 
 + 
 +**git checkout <file>** 
 +When you change your mind about the changes you've made, restore the file back to where it was before you started. 
 + 
 +**git checkout <commit>** 
 +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. 
 + 
 +Note that this results in a "detached HEAD"
 +The HEAD is a pointer to a commit. 
 +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 <branch> to implicitly reattach the HEAD. 
 + 
 +==== 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 "detached"
 + 
 +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 <branch> 
 +  git checkout <commit> 
 +  git checkout <file> 
 + 
 +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                ^ alias               ^ 
 +| git checkout <branch>  | git switch <branch> 
 +| git checkout <file>    | git restore <file>   | 
 + 
 + 
 + 
 + 
  
-(Note that checkout of a commit is extraordinary and results in a detached HEAD.) 
 ====diff==== ====diff====
  
Line 281: Line 331:
 By default diff compares all of the currently modified files. By default diff compares all of the currently modified files.
  
-  git diff         # before the add +  git diff           # before staging 
-  git add . +  git add .          # staging 
-  git diff HEAD    # after the add+  git diff HEAD      # after staging 
 +  git diff --staged  # after staging
  
 Additional options. Additional options.
Line 335: Line 386:
  
 https://www.sitepoint.com/git-interactive-rebase-guide/ https://www.sitepoint.com/git-interactive-rebase-guide/
 +
 +==== Combinations ====
 +
 +Some git command options effectively execute multiple git commands simultaneously.
 +Here are some examples.
 +
 +  1. git add .
 +  2. git commit -m 'latest fix'
 +  1+2. git -a commit -m 'latest fix'      # combine add and commit
 +
 +  1. git clone <project>
 +  2. git submodule init
 +  3. git submodule update
 +  2+3. git submodule update --init
 +  1+2+3. git clone --recursive-submodules <project> 
 +
 +  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.  A fork is a server-side clone.
 +
 +Locally:
 + git clone xttps://github.com/hagstrand/flash flashbang   # specified target <directory>
 + git remote add upstream xttps:github.com/voyc/flash   # second remote
 + git pull --rebase upstream master   # pull changes from upstream, update local, no commit
 + # pull does a fetch and merge into local directory.  No need to commit.
 + 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 616: Line 700:
  git submodule update --init   # copies entries from .gitmodules to .git/config, and pulls each  git submodule update --init   # copies entries from .gitmodules to .git/config, and pulls each
  
-==== Combinations ==== 
  
-Some git command options effectively execute multiple git commands simultaneously. 
-Here are some examples. 
  
-  1. git add . +==== Remove submodule ====
-  2. git commit -m 'latest fix' +
-  1+2. git -commit -m 'latest fix'      # combine add and commit+
  
-  1git clone <project+Remove a submodule but keep the working tree. 
-  2git submodule init +<code
-  3git submodule update +# 1Remove the submodule entry from .gitmodules 
-  2+3. git submodule update --init +git submodule deinit -f path/to/submodule
-  1+2+3. git clone --recursive-submodules <project> +
  
-  1. git fetch     download patch files +# 2. Remove it from git's index and the .git/modules cache 
-  2. git merge     # apply patches to local files +git rm -f path/to/submodule 
-  1+2. git pull    # fetch and merge+rm -rf .git/modules/path/to/submodule
  
-====Fork==== +3Commit the removal 
-In github ui, fork repo from voyc to hagstrand.  A fork is a server-side clone. +git commit -m "Remove submodule path/to/submodulekeep files as plain code"
- +
-Locally: +
- git clone xttps://github.com/hagstrand/flash flashbang   specified target <directory> +
- git remote add upstream xttps:github.com/voyc/flash   # second remote +
- git pull --rebase upstream master   # pull changes from upstream, update local, no commit +
- # pull does a fetch and merge into local directory.  No need to commit. +
- git push origin master    +
- Todo: Rename? +
- Todo: In github UI“Pull Request” to bring forked project back into upstream.+
  
-====See the current changes==== +# 4. Re-add the files as normal tracked files 
- git diff  # before staging (git add *) +git add path/to/submodule 
- git diff --staged # after staging+git commit -m "Add formerly-submoduled files as plain code" 
 +</code>
  
 =====Alternative Workflows===== =====Alternative Workflows=====
git.1781583197.txt.gz · Last modified: 2026/06/16 00:13 by jhagstrand

Except where otherwise noted, content on this wiki is licensed under the following license: Public Domain
Public Domain Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki