3 .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets v1.79.2 <http://docbook.sf.net/>
7 .\" Source: Git 2.47.0.rc0
10 .TH "GITEVERYDAY" "7" "2024-09-25" "Git 2\&.47\&.0\&.rc0" "Git Manual"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 giteveryday \- A useful minimum set of commands for Everyday Git
34 Everyday Git With 20 Commands Or So
37 Git users can broadly be grouped into four categories for the purposes of describing here a small set of useful commands for everyday Git\&.
47 Individual Developer (Standalone)
48 commands are essential for anybody who makes a commit, even for somebody who works alone\&.
59 If you work with other people, you will need commands listed in the
60 Individual Developer (Participant)
74 role need to learn some more commands in addition to the above\&.
85 Repository Administration
86 commands are for system administrators who are responsible for the care and feeding of Git repositories\&.
88 .SH "INDIVIDUAL DEVELOPER (STANDALONE)"
90 A standalone individual developer does not exchange patches with other people, and works alone in a single repository, using the following commands\&.
101 to create a new repository\&.
113 to see what happened\&.
127 to switch branches\&.
139 to manage the index file\&.
153 to see what you are in the middle of doing\&.
165 to advance the current branch\&.
189 to merge between local branches\&.
201 to maintain topic branches\&.
213 to mark a known point\&.
217 Use a tarball as a starting point for a new repository\&.
224 $ tar zxf frotz\&.tar\&.gz
227 $ git add \&. \fB(1)\fR
228 $ git commit \-m "import of frotz source tree\&."
229 $ git tag v2\&.43 \fB(2)\fR
236 r lw(\n(.lu*75u/100u).
238 add everything under the current directory\&.
241 make a lightweight, unannotated tag\&.
246 Create a topic branch and develop\&.
253 $ git switch \-c alsa\-audio \fB(1)\fR
255 $ git restore curses/ux_audio_oss\&.c \fB(2)\fR
256 $ git add curses/ux_audio_alsa\&.c \fB(3)\fR
258 $ git diff HEAD \fB(4)\fR
259 $ git commit \-a \-s \fB(5)\fR
261 $ git diff HEAD^ \fB(6)\fR
262 $ git commit \-a \-\-amend \fB(7)\fR
263 $ git switch master \fB(8)\fR
264 $ git merge alsa\-audio \fB(9)\fR
265 $ git log \-\-since=\*(Aq3 days ago\*(Aq \fB(10)\fR
266 $ git log v2\&.43\&.\&. curses/ \fB(11)\fR
273 r lw(\n(.lu*75u/100u).
275 create a new topic branch\&.
278 revert your botched changes in
279 \fBcurses/ux_audio_oss\&.c\fR\&.
282 you need to tell Git if you added a new file; removal and modification will be caught if you do
287 to see what changes you are committing\&.
290 commit everything, as you have tested, with your sign\-off\&.
293 look at all your changes including the previous commit\&.
296 amend the previous commit, adding all your new changes, using your original message\&.
299 switch to the master branch\&.
302 merge a topic branch into your master branch\&.
305 review commit logs; other forms to limit output can be combined and include
307 (to show up to 10 commits),
308 \fB\-\-until=2005\-12\-10\fR, etc\&.
311 view only the changes that touch what\(cqs in
319 .SH "INDIVIDUAL DEVELOPER (PARTICIPANT)"
321 A developer working as a participant in a group project needs to learn how to communicate with others, and uses these commands in addition to the ones needed by a standalone developer\&.
332 from the upstream to prime your local repository\&.
346 from "origin" to keep up\-to\-date with the upstream\&.
358 to shared repository, if you adopt CVS style shared repository workflow\&.
369 \fBgit-format-patch\fR(1)
370 to prepare e\-mail submission, if you adopt Linux kernel\-style public forum workflow\&.
381 \fBgit-send-email\fR(1)
382 to send your e\-mail submission without corruption by your MUA\&.
393 \fBgit-request-pull\fR(1)
394 to create a summary of changes for your upstream to pull\&.
398 Clone the upstream and work on it\&. Feed changes to upstream\&.
405 $ git clone git://git\&.kernel\&.org/pub/scm/\&.\&.\&./torvalds/linux\-2\&.6 my2\&.6
407 $ git switch \-c mine master \fB(1)\fR
408 $ edit/compile/test; git commit \-a \-s \fB(2)\fR
409 $ git format\-patch master \fB(3)\fR
410 $ git send\-email \-\-to="person <email@example\&.com>" 00*\&.patch \fB(4)\fR
411 $ git switch master \fB(5)\fR
413 $ git log \-p ORIG_HEAD\&.\&. arch/i386 include/asm\-i386 \fB(7)\fR
414 $ git ls\-remote \-\-heads http://git\&.kernel\&.org/\&.\&.\&./jgarzik/libata\-dev\&.git \fB(8)\fR
415 $ git pull git://git\&.kernel\&.org/pub/\&.\&.\&./jgarzik/libata\-dev\&.git ALL \fB(9)\fR
416 $ git reset \-\-hard ORIG_HEAD \fB(10)\fR
424 r lw(\n(.lu*75u/100u).
426 checkout a new branch
434 extract patches from your branch, relative to master,
441 \fBmaster\fR, ready to see what\(cqs new
447 by default and merges into the current branch\&.
450 immediately after pulling, look at the changes done upstream since last time we checked, only in the area we are interested in\&.
453 check the branch names in an external repository (if not known)\&.
456 fetch from a specific branch
458 from a specific repository and merge it\&.
464 garbage collect leftover objects from reverted pull\&.
469 Push into another repository\&.
476 satellite$ git clone mothership:frotz frotz \fB(1)\fR
478 satellite$ git config \-\-get\-regexp \*(Aq^(remote|branch)\e\&.\*(Aq \fB(2)\fR
479 remote\&.origin\&.url mothership:frotz
480 remote\&.origin\&.fetch refs/heads/*:refs/remotes/origin/*
481 branch\&.master\&.remote origin
482 branch\&.master\&.merge refs/heads/master
483 satellite$ git config remote\&.origin\&.push \e
484 +refs/heads/*:refs/remotes/satellite/* \fB(3)\fR
485 satellite$ edit/compile/test/commit
486 satellite$ git push origin \fB(4)\fR
489 mothership$ git switch master
490 mothership$ git merge satellite/master \fB(5)\fR
497 r lw(\n(.lu*75u/100u).
499 mothership machine has a frotz repository under your home directory; clone from it to start a repository on the satellite machine\&.
502 clone sets these configuration variables by default\&. It arranges
504 to fetch and store the branches of mothership machine to local
505 \fBremotes/origin/*\fR
506 remote\-tracking branches\&.
511 to push all local branches to their corresponding branch of the mothership machine\&.
514 push will stash all our work away on
515 \fBremotes/satellite/*\fR
516 remote\-tracking branches on the mothership machine\&. You could use this as a back\-up method\&. Likewise, you can pretend that mothership "fetched" from you (useful when access is one sided)\&.
519 on mothership machine, merge the work done on the satellite machine into the master branch\&.
524 Branch off of a specific tag\&.
531 $ git switch \-c private2\&.6\&.14 v2\&.6\&.14 \fB(1)\fR
532 $ edit/compile/test; git commit \-a
533 $ git checkout master
534 $ git cherry\-pick v2\&.6\&.14\&.\&.private2\&.6\&.14 \fB(2)\fR
541 r lw(\n(.lu*75u/100u).
543 create a private branch based on a well known (but somewhat behind) tag\&.
546 forward port all changes in
547 \fBprivate2\&.6\&.14\fR
550 branch without a formal "merging"\&. Or longhand
552 \fBgit format\-patch \-k \-m \-\-stdout v2\&.6\&.14\&.\&.private2\&.6\&.14 | git am \-3 \-k\fR
557 An alternate participant submission mechanism is using the \fBgit request\-pull\fR or pull\-request mechanisms (e\&.g\&. as used on GitHub (www\&.github\&.com) to notify your upstream of your contribution\&.
560 A fairly central person acting as the integrator in a group project receives changes made by others, reviews and integrates them and publishes the result for others to use, using these commands in addition to the ones needed by participants\&.
562 This section can also be used by those who respond to \fBgit request\-pull\fR or pull\-request on GitHub (www\&.github\&.com) to integrate the work of others into their history\&. A sub\-area lieutenant for a repository will act both as a participant and as an integrator\&.
573 to apply patches e\-mailed in from your contributors\&.
585 to merge from your trusted lieutenants\&.
596 \fBgit-format-patch\fR(1)
597 to prepare and send suggested alternative to contributors\&.
609 to undo botched commits\&.
621 to publish the bleeding edge\&.
625 A typical integrator\(cqs Git day\&.
632 $ git status \fB(1)\fR
633 $ git branch \-\-no\-merged master \fB(2)\fR
635 & s 2 3 4 5 \&./+to\-apply
636 & s 7 8 \&./+hold\-linus
638 $ git switch \-c topic/one master
639 $ git am \-3 \-i \-s \&./+to\-apply \fB(4)\fR
641 $ git switch \-c hold/linus && git am \-3 \-i \-s \&./+hold\-linus \fB(5)\fR
642 $ git switch topic/one && git rebase master \fB(6)\fR
643 $ git switch \-C seen next \fB(7)\fR
644 $ git merge topic/one topic/two && git merge hold/linus \fB(8)\fR
646 $ git cherry\-pick master~4 \fB(9)\fR
648 $ git tag \-s \-m "GIT 0\&.99\&.9x" v0\&.99\&.9x \fB(10)\fR
649 $ git fetch ko && for branch in master maint next seen \fB(11)\fR
651 git show\-branch ko/$branch $branch \fB(12)\fR
653 $ git push \-\-follow\-tags ko \fB(13)\fR
660 r lw(\n(.lu*75u/100u).
662 see what you were in the middle of doing, if anything\&.
665 see which branches haven\(cqt been merged into
667 yet\&. Likewise for any other integration branches e\&.g\&.
674 read mails, save ones that are applicable, and save others that are not quite ready (other mail readers are available)\&.
677 apply them, interactively, with your sign\-offs\&.
680 create topic branch as needed and apply, again with sign\-offs\&.
683 rebase internal topic branch that has not been merged to the master or exposed as a part of a stable branch\&.
688 every time from the next\&.
691 and bundle topic branches still cooking\&.
694 backport a critical fix\&.
697 create a signed tag\&.
700 make sure master was not accidentally rewound beyond that already pushed out\&.
704 \fBgit show\-branch\fR,
706 should have everything
710 should have everything
715 push out the bleeding edge, together with new tags that point into the pushed history\&.
720 In this example, the \fBko\fR shorthand points at the Git maintainer\(cqs repository at kernel\&.org, and looks like this:
728 url = kernel\&.org:/pub/scm/git/git\&.git
729 fetch = refs/heads/*:refs/remotes/ko/*
730 push = refs/heads/master
731 push = refs/heads/next
732 push = +refs/heads/seen
733 push = refs/heads/maint
738 .SH "REPOSITORY ADMINISTRATION"
740 A repository administrator uses the following tools to set up and maintain access to the repository by developers\&.
751 to allow anonymous download from repository\&.
764 \fIrestricted login shell\fR
765 for shared central repository users\&.
776 \fBgit-http-backend\fR(1)
777 provides a server side implementation of Git\-over\-HTTP ("Smart http") allowing both fetch and push services\&.
789 provides a web front\-end to Git repositories, which can be set\-up using the
790 \fBgit-instaweb\fR(1)
794 \m[blue]\fBupdate hook howto\fR\m[]\&\s-2\u[1]\d\s+2 has a good example of managing a shared central repository\&.
796 In addition there are a number of other widely deployed hosting, browsing and reviewing solutions such as:
806 gitolite, gerrit code review, cgit and others\&.
810 We assume the following in /etc/services
817 $ grep 9418 /etc/services
818 git 9418/tcp # Git Version Control System
825 Run git\-daemon to serve /pub/scm from inetd\&.
832 $ grep git /etc/inetd\&.conf
833 git stream tcp nowait nobody \e
834 /usr/bin/git\-daemon git\-daemon \-\-inetd \-\-export\-all /pub/scm
840 The actual configuration line should be on one line\&.
843 Run git\-daemon to serve /pub/scm from xinetd\&.
850 $ cat /etc/xinetd\&.d/git\-daemon
852 # description: The Git server offers access to Git repositories
861 server = /usr/bin/git\-daemon
862 server_args = \-\-inetd \-\-export\-all \-\-base\-path=/pub/scm
863 log_on_failure += USERID
870 Check your xinetd(8) documentation and setup, this is from a Fedora system\&. Others might be different\&.
873 Give push/pull only access to developers using git\-over\-ssh\&.
875 e\&.g\&. those using:
876 \fB$ git push/pull ssh://host\&.xz/pub/scm/project\fR
882 $ grep git /etc/passwd \fB(1)\fR
883 alice:x:1000:1000::/home/alice:/usr/bin/git\-shell
884 bob:x:1001:1001::/home/bob:/usr/bin/git\-shell
885 cindy:x:1002:1002::/home/cindy:/usr/bin/git\-shell
886 david:x:1003:1003::/home/david:/usr/bin/git\-shell
887 $ grep git /etc/shells \fB(2)\fR
895 r lw(\n(.lu*75u/100u).
897 log\-in shell is set to /usr/bin/git\-shell, which does not allow anything but
900 \fBgit pull\fR\&. The users require ssh access to the machine\&.
903 in many distributions /etc/shells needs to list what is used as the login shell\&.
908 CVS\-style shared repository\&.
915 $ grep git /etc/group \fB(1)\fR
916 git:x:9418:alice,bob,cindy,david
917 $ cd /home/devo\&.git
919 lrwxrwxrwx 1 david git 17 Dec 4 22:40 HEAD \-> refs/heads/master
920 drwxrwsr\-x 2 david git 4096 Dec 4 22:40 branches
921 \-rw\-rw\-r\-\- 1 david git 84 Dec 4 22:40 config
922 \-rw\-rw\-r\-\- 1 david git 58 Dec 4 22:40 description
923 drwxrwsr\-x 2 david git 4096 Dec 4 22:40 hooks
924 \-rw\-rw\-r\-\- 1 david git 37504 Dec 4 22:40 index
925 drwxrwsr\-x 2 david git 4096 Dec 4 22:40 info
926 drwxrwsr\-x 4 david git 4096 Dec 4 22:40 objects
927 drwxrwsr\-x 4 david git 4096 Nov 7 14:58 refs
928 drwxrwsr\-x 2 david git 4096 Dec 4 22:40 remotes
929 $ ls \-l hooks/update \fB(3)\fR
930 \-r\-xr\-xr\-x 1 david git 3536 Dec 4 22:40 update
931 $ cat info/allowed\-users \fB(4)\fR
932 refs/heads/master alice\e|cindy
933 refs/heads/doc\-update bob
934 refs/tags/v[0\-9]* david
941 r lw(\n(.lu*75u/100u).
943 place the developers into the same git group\&.
946 and make the shared repository writable by the group\&.
949 use update\-hook example by Carl from Documentation/howto/ for branch policy control\&.
952 alice and cindy can push into master, only bob can push into doc\-update\&. david is the release manager and is the only person who can create and push version tags\&.
958 Part of the \fBgit\fR(1) suite
963 \%git-htmldocs/howto/update-hook-example.html