### Example .gitattributes configuration Source: https://git-scm.com/docs/git-check-attr This configuration file defines attributes for various file patterns used in the examples. ```text *.java diff=java -crlf myAttr NoMyAttr.java !myAttr README caveat=unspecified ``` -------------------------------- ### Example pre-push input Source: https://git-scm.com/docs/githooks An example of the input received by the pre-push hook for a specific push command. ```text refs/heads/master 67890 refs/heads/foreign 12345 ``` -------------------------------- ### Launch git-gui Source: https://git-scm.com/docs/git-gui Basic command to start the git-gui application. ```bash git gui [] [] ``` -------------------------------- ### Process Start Event Source: https://git-scm.com/docs/api-trace2 Contains the complete command-line arguments received by the process. ```json { "event":"start", ... "t_abs":0.001227, # elapsed time in seconds "argv":["git","version"] } ``` -------------------------------- ### Merge Index Example Source: https://git-scm.com/docs/git-merge-index Examples demonstrating how git-merge-index processes files needing a merge. ```bash torvalds@ppc970:~/merge-test> git merge-index cat MM This is MM from the original tree. # original This is modified MM in the branch A. # merge1 This is modified MM in the branch B. # merge2 This is modified MM in the branch B. # current contents ``` ```bash torvalds@ppc970:~/merge-test> git merge-index cat AA MM cat: : No such file or directory This is added AA in the branch A. This is added AA in the branch B. This is added AA in the branch B. fatal: merge program failed ``` -------------------------------- ### Initialize bisection with specific commits Source: https://git-scm.com/docs/git-bisect-lk2009 Example of starting a bisect session between two specific versions. ```bash $ git bisect start v2.6.27 v2.6.25 Bisecting: 10928 revisions left to test after this (roughly 14 steps) [2ec65f8b89ea003c27ff7723525a2ee335a2b393] x86: clean up using max_low_pfn on 32-bit ``` -------------------------------- ### Install Apache on Debian Source: https://git-scm.com/docs/howto/setup-git-server-over-http Commands to install and enable the Apache2 web server on Debian-based systems. ```bash On Debian: $ apt-get install apache2 To get apache2 by default started, edit /etc/default/apache2 and set NO_START=0 ``` -------------------------------- ### Connect via pserver Source: https://git-scm.com/docs/git-cvsserver Example command to checkout a repository using the pserver method. ```bash cvs -d:pserver:someuser:somepassword@server:/path/repo.git co ``` -------------------------------- ### Git Patch Swap Example Source: https://git-scm.com/docs/git-diff-pairs An example of a patch that swaps two files, demonstrating that changes are not applied sequentially. ```text diff --git a/a b/b rename from a rename to b diff --git a/b b/a rename from b rename to a ``` -------------------------------- ### Bisection algorithm output example Source: https://git-scm.com/docs/git-bisect-lk2009 Example output showing commit hashes and their associated bisection distance values. ```text e15b73ad3db9b48d7d1ade32f8cd23a751fe0ace (dist=3) 15722f2fa328eaba97022898a305ffc8172db6b1 (dist=2) 78e86cf3e850bd755bb71831f42e200626fbd1e0 (dist=2) a1939d9a142de972094af4dde9a544e577ddef0e (dist=2) 070eab2303024706f2924822bfec8b9847e4ac1b (dist=1) a3864d4f32a3bf5ed177ddef598490a08760b70d (dist=1) a41baa717dd74f1180abf55e9341bc7a0bb9d556 (dist=1) 9e622a6dad403b71c40979743bb9d5be17b16bd6 (dist=0) ``` -------------------------------- ### git-stripspace Examples Source: https://git-scm.com/docs/git-stripspace Demonstration of input cleaning and comment stripping. ```text |A brief introduction $ | $ |$ |A new paragraph$ |# with a commented-out line $ |explaining lots of stuff.$ |$ |# An old paragraph, also commented-out. $ | $ |The end.$ | $ ``` ```text |A brief introduction$ |$ |A new paragraph$ |# with a commented-out line$ |explaining lots of stuff.$ |$ |# An old paragraph, also commented-out.$ |$ |The end.$ ``` ```text |A brief introduction$ |$ |A new paragraph$ |explaining lots of stuff.$ |$ |The end.$ ``` -------------------------------- ### Example of specific GPG signature headers Source: https://git-scm.com/docs/git-fast-export Examples of how OpenPGP and SSH signatures appear for different hash algorithms. ```text gpgsig sha1 openpgp gpgsig sha256 ssh ``` -------------------------------- ### git-daemon command synopsis Source: https://git-scm.com/docs/git-daemon The command-line syntax for configuring and starting the git-daemon server. ```bash git daemon [--verbose] [--syslog] [--export-all] [--timeout=] [--init-timeout=] [--max-connections=] [--strict-paths] [--base-path=] [--base-path-relaxed] [--user-path | --user-path=] [--interpolated-path=] [--reuseaddr] [--detach] [--pid-file=] [--enable=] [--disable=] [--allow-override=] [--forbid-override=] [--access-hook=] [--[no-]informative-errors] [--inetd | [--listen=] [--port=] [--user= [--group=]]] [--log-destination=(stderr|syslog|none)] […] ``` -------------------------------- ### Topology Example 2 Source: https://git-scm.com/docs/git-merge-base Visual representation of a three-commit merge base scenario. ```text o---o---o---o---C / / o---o---o---B / / ---2---1---o---o---o---A ``` -------------------------------- ### Deprecated subsection configuration example Source: https://git-scm.com/docs/git-config Initial configuration state using the deprecated section.subsection syntax. ```ini [section.subsection] key = value1 ``` -------------------------------- ### Start development from a known tag Source: https://git-scm.com/docs/git-branch Creates a new branch based on a specific tag and switches to it. ```bash $ git clone git://git.kernel.org/pub/scm/.../linux-2.6 my2.6 $ cd my2.6 $ git branch my2.6.14 v2.6.14 **(1)** $ git switch my2.6.14 ``` -------------------------------- ### Initialize Example Submodule Repositories Source: https://git-scm.com/docs/user-manual Creates four local repositories to serve as submodules for demonstration purposes. ```bash $ mkdir ~/git $ cd ~/git $ for i in a b c d do mkdir $i cd $i git init echo "module $i" > $i.txt git add $i.txt git commit -m "Initial commit, submodule $i" cd .. done ``` -------------------------------- ### Example .git/config file structure Source: https://git-scm.com/docs/git-config A sample configuration file demonstrating comments, sections, and multivar entries. ```ini # # This is the config file, and # a '#' or ';' character indicates # a comment # ; core variables [core] ; Don't trust file modes filemode = false ; Our diff algorithm [diff] external = /usr/local/bin/diff-wrapper renames = true ; Proxy settings [core] gitproxy=proxy-command for kernel.org gitproxy=default-proxy ; for all the rest ; HTTP [http] sslVerify [http "https://weak.example.com"] sslVerify = false cookieFile = /tmp/cookie.txt ``` -------------------------------- ### Thread Start Event Source: https://git-scm.com/docs/api-trace2 Generated from within a new thread when it starts. ```json { "event":"thread_start", ... "thread":"th02:preload_thread" # thread name } ``` -------------------------------- ### Example repository URLs Source: https://git-scm.com/docs/gitweb.conf Demonstrates how project paths map to filesystem locations via Gitweb URLs. ```text http://git.example.com/gitweb.cgi?p=foo/bar.git ``` ```text http://git.example.com/gitweb.cgi/foo/bar.git ``` -------------------------------- ### Start Interactive Rebase Source: https://git-scm.com/docs/git-rebase Initiates an interactive rebase session starting after the specified commit. ```bash git rebase -i ``` -------------------------------- ### Create a bare repository Source: https://git-scm.com/docs/git-clone Initializes a bare repository for public publishing. ```bash $ git clone --bare -l /home/proj/.git /pub/scm/proj.git ``` -------------------------------- ### Represent pkt-line Examples Source: https://git-scm.com/docs/gitprotocol-common Examples of pkt-line strings and their corresponding decoded payload values. ```text pkt-line actual value --------------------------------- "0006a\n" "a\n" "0005a" "a" "000bfoobar\n" "foobar\n" "0004" "" ``` -------------------------------- ### Initialize a new repository Source: https://git-scm.com/docs/user-manual Commands to create a new repository from scratch or from existing project files. ```bash $ mkdir project $ cd project $ git init ``` ```bash $ tar xzvf project.tar.gz $ cd project $ git init $ git add . # include everything below ./ in the first commit: $ git commit ``` -------------------------------- ### PERF Format Example Output Source: https://git-scm.com/docs/api-trace2 Example output lines for the PERF target format. ```text 15:33:33.532712 wt-status.c:2310 | d0 | main | region_enter | r1 | 0.126064 | | status | label:print 15:33:33.532712 wt-status.c:2331 | d0 | main | region_leave | r1 | 0.127568 | 0.001504 | status | label:print ``` -------------------------------- ### Example gitattributes file configurations Source: https://git-scm.com/docs/gitattributes Sample configurations across different gitattributes files to demonstrate attribute precedence. ```gitattributes (in $GIT_DIR/info/attributes) a* foo !bar -baz (in .gitattributes) abc foo bar baz (in t/.gitattributes) ab* merge=filfre abc -foo -bar *.c frotz ``` -------------------------------- ### Create bundles with references Source: https://git-scm.com/docs/git-bundle Examples of creating bundles using explicit branch names or standard input. ```bash $ git bundle create master.bundle master $ echo master | git bundle create master.bundle --stdin $ git bundle create master-and-next.bundle master next $ (echo master; echo next) | git bundle create master-and-next.bundle --stdin ``` -------------------------------- ### Ignore paths examples Source: https://git-scm.com/docs/git-svn Examples of using Perl regular expressions to ignore specific directory patterns. ```bash --ignore-paths="^doc" ``` ```bash --ignore-paths="^[^/]+/(?:branches|tags)" ``` -------------------------------- ### Configure push.pushOption Source: https://git-scm.com/docs/git-push Demonstrates how to use multi-valued push.pushOption variables across different configuration files to clear and set options. ```text /etc/gitconfig push.pushoption = a push.pushoption = b ~/.gitconfig push.pushoption = c repo/.git/config push.pushoption = push.pushoption = b This will result in only b (a and c are cleared). ``` -------------------------------- ### Create bundles with specific prerequisites Source: https://git-scm.com/docs/git-bundle Demonstrates creating bundles using tags, time-based constraints, or commit counts as prerequisites. ```bash $ git bundle create mybundle v1.0.0..master ``` ```bash $ git bundle create mybundle --since=10.days master ``` ```bash $ git bundle create mybundle -10 master ``` -------------------------------- ### Commit History Topology Example Source: https://git-scm.com/docs/git-replay Example of a commit history structure used to demonstrate ordering differences. ```text ---1----2----4----7 \ \ 3----5----6----8--- ``` -------------------------------- ### Initialize a Shared Bare Repository Source: https://git-scm.com/docs/gitcvs-migration Creates a bare repository and fetches an existing project into it to enable shared access. ```bash $ mkdir /pub/my-repo.git $ cd /pub/my-repo.git $ git --bare init --shared $ git --bare fetch /home/alice/myproject master:master ``` -------------------------------- ### Combined Diff Output Example Source: https://git-scm.com/docs/git-diff-pairs A full example of a combined diff output showing changes in a merge commit. ```text diff --combined describe.c index fabadb8,cc95eb0..4866510 --- a/describe.c +++ b/describe.c @@@ -98,20 -98,12 +98,20 @@@ return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1; } - static void describe(char *arg) -static void describe(struct commit *cmit, int last_one) ++static void describe(char *arg, int last_one) { + unsigned char sha1[20]; + struct commit *cmit; struct commit_list *list; static int initialized = 0; struct commit_name *n; + if (get_sha1(arg, sha1) < 0) + usage(describe_usage); + cmit = lookup_commit_reference(sha1); + if (!cmit) + usage(describe_usage); + if (!initialized) { initialized = 1; for_each_ref(get_name); ``` -------------------------------- ### Initialize a Git repository Source: https://git-scm.com/docs/git-init The standard syntax for initializing a Git repository with various configuration options. ```bash git init [-q | --quiet] [--bare] [--template=__] [--separate-git-dir __] [--object-format=__] [--ref-format=__] [-b __ | --initial-branch=__] [--shared[=__]] [__] ``` -------------------------------- ### Initialize the bare repository Source: https://git-scm.com/docs/howto/setup-git-server-over-http Initialize the directory as a bare Git repository. ```bash $ cd my-new-repo.git $ git --bare init ``` -------------------------------- ### Initialize a new repository Source: https://git-scm.com/docs/gittutorial Extract a project archive and initialize a new Git repository. ```bash $ tar xzf project.tar.gz $ cd project $ git init ``` -------------------------------- ### Example client/server communication Source: https://git-scm.com/docs/gitprotocol-pack A sample exchange showing reference discovery, client push, and server report-status response. ```text S: 006274730d410fcb6603ace96f1dc55ea6196122532d refs/heads/local\0report-status delete-refs ofs-delta\n S: 003e7d1665144a3a975c05f1f43902ddaf084e784dbe refs/heads/debug\n S: 003f74730d410fcb6603ace96f1dc55ea6196122532d refs/heads/master\n S: 003d74730d410fcb6603ace96f1dc55ea6196122532d refs/heads/team\n S: 0000 C: 00677d1665144a3a975c05f1f43902ddaf084e784dbe 74730d410fcb6603ace96f1dc55ea6196122532d refs/heads/debug\n C: 006874730d410fcb6603ace96f1dc55ea6196122532d 5a3f6be755bbb7deae50065988cbfa1ffa9ab68a refs/heads/master\n C: 0000 C: [PACKDATA] S: 000eunpack ok\n S: 0018ok refs/heads/debug\n S: 002ang refs/heads/master non-fast-forward\n ``` -------------------------------- ### Create Superproject and Add Submodules Source: https://git-scm.com/docs/user-manual Initializes a new repository and adds the previously created repositories as submodules. ```bash $ mkdir super $ cd super $ git init $ for i in a b c d do git submodule add ~/git/$i $i done ``` -------------------------------- ### Check Git Version Source: https://git-scm.com/docs/git-bugreport Verify the installed version of Git. ```bash git --version ``` -------------------------------- ### Initialize a bare repository Source: https://git-scm.com/docs/gitcore-tutorial Create a Git repository in a directory not named .git by specifying the GIT_DIR environment variable. ```bash $ GIT_DIR=my-git.git git init ``` -------------------------------- ### Submodule Repository Request Source: https://git-scm.com/docs/gitprotocol-http Example of a request made to a submodule repository. ```text $GIT_URL: http://example.com/git/repo.git/path/submodule.git URL request: http://example.com/git/repo.git/path/submodule.git/info/refs ``` -------------------------------- ### Case-insensitive matching example Source: https://git-scm.com/docs/gitmailmap Demonstrates that matching is case-insensitive for both names and emails. ```text Proper Name CoMmIt NaMe ``` -------------------------------- ### Find and Configure Credential Helpers Source: https://git-scm.com/docs/gitcredentials Commands to list available credential helpers, view their documentation, and enable them globally. ```bash $ git help -a | grep credential- credential-foo ``` ```bash $ git help credential-foo ``` ```bash $ git config --global credential.helper foo ``` -------------------------------- ### Example range-diff output Source: https://git-scm.com/docs/git-range-diff A representation of the output format for a range-diff operation. ```text -: ------- > 1: 0ddba11 Prepare for the inevitable! 1: c0debee = 2: cab005e Add a helpful message at the start 2: f00dbal ! 3: decafe1 Describe a bug @@ -1,3 +1,3 @@ Author: A U Thor -TODO: Describe a bug +Describe a bug @@ -324,5 +324,6 This is expected. -+What is unexpected is that it will also crash. ++Unexpectedly, it also crashes. This is a bug, and the jury is ++still out there how to fix it best. See ticket #314 for details. Contact 3: bedead < -: ------- TO-UNDO ``` -------------------------------- ### git-instaweb Synopsis Source: https://git-scm.com/docs/git-instaweb Usage patterns for starting, stopping, and configuring the git-instaweb server. ```bash _git instaweb_ [--local] [--httpd=] [--port=] [--browser=] _git instaweb_ [--start] [--stop] [--restart] ``` -------------------------------- ### Example repository structure for symlink testing Source: https://git-scm.com/docs/git-cat-file A sample file structure used to demonstrate symlink resolution behavior. ```text f: a file containing "hello\n" link: a symlink to f dir/link: a symlink to ../f plink: a symlink to ../f alink: a symlink to /etc/passwd ``` -------------------------------- ### Initialize and commit in a new repository Source: https://git-scm.com/docs/gittutorial-2 Create a new directory, initialize a Git repository, and perform initial commits to generate history. ```bash $ mkdir test-project $ cd test-project $ git init Initialized empty Git repository in .git/ $ echo 'hello world' > file.txt $ git add . $ git commit -a -m "initial commit" [master (root-commit) 54196cc] initial commit 1 file changed, 1 insertion(+) create mode 100644 file.txt $ echo 'hello world!' >file.txt $ git commit -a -m "add emphasis" [master c4d59f3] add emphasis 1 file changed, 1 insertion(+), 1 deletion(-) ``` -------------------------------- ### Create a text file for hashing Source: https://git-scm.com/docs/user-manual Initializes a simple text file to demonstrate Git object hashing. ```bash $ echo "Hello world" >hello.txt ``` -------------------------------- ### Start git bisect Source: https://git-scm.com/docs/git-bisect-lk2009 Command to initiate a bisect session on the new branch. ```bash $ git bisect start Z' Y ``` -------------------------------- ### Optimize Bisect Start Source: https://git-scm.com/docs/git-bisect Narrow the search space by specifying paths or multiple known good commits at startup. ```bash $ git bisect start -- arch/i386 include/asm-i386 ``` ```bash $ git bisect start v2.6.20-rc6 v2.6.20-rc4 v2.6.20-rc1 -- # v2.6.20-rc6 is bad # v2.6.20-rc4 and v2.6.20-rc1 are good ``` -------------------------------- ### Pull using remote shorthand Source: https://git-scm.com/docs/gitcore-tutorial Examples of pulling from a configured remote alias. ```bash git pull linus ``` ```bash git pull linus tag v0.99.1 ``` -------------------------------- ### Initialize a new repository Source: https://git-scm.com/docs/user-manual Commands to initialize a Git repository from a local directory or clone an existing remote repository. ```bash $ tar xzf project.tar.gz $ cd project $ git init Initialized empty Git repository in .git/ $ git add . $ git commit ``` ```bash $ git clone git://example.com/pub/project.git $ cd project ``` -------------------------------- ### Define Authentication Configuration Source: https://git-scm.com/docs/git-http-backend Example content for the git-auth.conf file used to enforce basic authentication. ```lighttpd auth.require = ( "/" => ( "method" => "basic", "realm" => "Git Access", "require" => "valid-user" ) ) # ...and set up auth.backend here ``` -------------------------------- ### Specify SSH username Source: https://git-scm.com/docs/git-svn Example of including a username in an svn+ssh URL for authentication. ```bash svn+ssh://foo@svn.bar.com/project ``` -------------------------------- ### Configure and Log Interesting Config Values Source: https://git-scm.com/docs/api-trace2 Demonstrates setting configuration scopes and using GIT_TRACE2_CONFIG_PARAMS to log specific configuration values to the performance trace log. ```bash $ git config --system color.ui never $ git config --global color.ui always $ git config --local color.ui auto $ git config list --show-scope | grep 'color.ui' system color.ui=never global color.ui=always local color.ui=auto ``` ```bash $ export GIT_TRACE2_PERF_BRIEF=1 $ export GIT_TRACE2_PERF=~/log.perf $ export GIT_TRACE2_CONFIG_PARAMS=color.ui $ git version ... $ cat ~/log.perf d0 | main | version | | | | | ... d0 | main | start | | 0.001642 | | | /usr/local/bin/git version d0 | main | cmd_name | | | | | version (version) d0 | main | def_param | | | | scope:system | color.ui:never d0 | main | def_param | | | | scope:global | color.ui:always d0 | main | def_param | | | | scope:local | color.ui:auto d0 | main | data | r0 | 0.002100 | 0.002100 | fsync | fsync/writeout-only:0 d0 | main | data | r0 | 0.002126 | 0.002126 | fsync | fsync/hardware-flush:0 d0 | main | exit | | 0.000470 | | | code:0 d0 | main | atexit | | 0.000477 | | | code:0 ``` -------------------------------- ### Example filepair entry Source: https://git-scm.com/docs/gitdiffcore A raw filepair entry representing a modified file. ```text :100644 100644 bcd1234... 0123456... M junkfile ``` -------------------------------- ### Configure credential for a different host Source: https://git-scm.com/docs/gitcredentials Example of a configuration entry that will not match the example.com context due to a differing hostname. ```ini [credential "https://kernel.org"] username = foo ``` -------------------------------- ### Out of sync file example Source: https://git-scm.com/docs/git-diff-files Shows the representation of a file on the filesystem that is out of sync with the index. ```text :100644 100644 5be4a4a 0000000 M file.c ``` -------------------------------- ### Non-Optimal Graph Calculation Source: https://git-scm.com/docs/git-bisect-lk2009 The result of applying the non-optimal function to the example graph. ```text 4 3 2 1 G-H-I-J 1 2 3 4 5 6/ \0 A-B-C-D-E-F O \ / K-L-M-N 4 3 2 1 ``` -------------------------------- ### Create input file for fast-import Source: https://git-scm.com/docs/git-fast-import Example of creating an input file with a deliberate error to trigger a crash. ```bash $ cat >in < 19283 -0400 # who is that guy anyway? data </my-new-repo.git ``` -------------------------------- ### Child Process Ready Event Source: https://git-scm.com/docs/api-trace2 Generated after a background process is started and handles are released. ```json { "event":"child_ready", ... "child_id":2, "pid":14708, # child PID "ready":"ready", # child ready state "t_rel":0.110605 # observed run-time of child process } ``` -------------------------------- ### Configure and use git-credential-store Source: https://git-scm.com/docs/git-credential-store Enables the credential store helper and demonstrates the automatic authentication flow. ```bash $ git config credential.helper store $ git push http://example.com/repo.git Username: Password: [several days later] $ git push http://example.com/repo.git [your credentials are used automatically] ``` -------------------------------- ### Interactive rebase command Source: https://git-scm.com/docs/git-bisect-lk2009 Command to start an interactive rebase for creating a special branch. ```bash $ git rebase -i Y Z ``` -------------------------------- ### Initialize and validate cat-file arguments Source: https://git-scm.com/docs/user-manual Configures the repository and validates the command-line arguments for the cat-file builtin. ```c repo_config(the_repository, git_default_config); if (argc != 3) usage("git cat-file [-t|-s|-e|-p|] "); if (get_sha1(argv[2], sha1)) die("Not a valid object name %s", argv[2]); ``` -------------------------------- ### Start bisect with multiple branches Source: https://git-scm.com/docs/git-bisect-lk2009 Command to initiate a bisection across different branches. ```bash $ git bisect start dev main ``` -------------------------------- ### Initialize a new Git repository Source: https://git-scm.com/docs/gitcore-tutorial Creates a new directory and initializes the Git infrastructure within it. ```bash $ mkdir git-tutorial $ cd git-tutorial $ git init ```