A completely ignorant, childish person with no manners.
$ /dont-panic/
note to self, use the bloody command line. It works!
— Channing Walton (@channingwalton) January 20, 2012
$ git <verb>
$ git help <verb> $ git <verb> --help
$ git init Initialized empty Git repository in /scratch/.git/ $ echo hello, world > hello.txt $ git add hello.txt $ git commit --message 'my first commit!' [master (root-commit) deadbee] my first commit! 1 file changed, 1 insertion(+) create mode 100644 hello.txt
$ git show commit deadbeef16165bb95a541321a7acf9cef9731c1d Author: Alexander Groß <agross@therightstuff.de> Date: Sat Feb 6 12:41:24 2010 +0100 my first commit! diff --git a/hello.txt b/hello.txt new file mode 100644 index 0000000..4b5fa63 --- /dev/null +++ b/hello.txt @@ -0,0 +1 @@ +hello, world
$ git add --patch $ git reset HEADrestore --staged --patch $ git checkoutrestore --patch
$ git update-index --[no-]skip-worktree
$ git ls-files -v | grep '^h'
Here are some better alternative names for the "master" branch in your source code repository:
— Markus Tacker 🇳🇴 (@coderbyheart) March 6, 2018
- bleeding-edge
- nevergreen
- works-on-my-machine
- happy-merging-XD
- there-be-real-users
- features-come-here-to-die
- (L°O°)L_|_|_
HEAD
pointer$ git branch topic [<where>]
(<where>
defaults to HEAD
)
HEAD
is$ git checkoutswitch topic
$ git checkout -bswitch -c <name> [<where>] == $ git branch <name> [<where>] && git checkoutswitch <name>
topic
branch$ git commit -am "work on topic"
master
$ git checkoutswitch master
HEAD
's position changes your working copy will be updated.Uncommitted changes will be attempted to be preserved.
master
branch$ git commit -am "work on master"
HEAD
HEAD
$ git checkoutswitch --detach deadbeef Note: checking out 'deadbeef'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them…HEAD is now at deadbeef
You're on no branch when you checkout
a SHA, tag or
remote branch.
$ git reflog 6bbd21d HEAD@{0}: commit (amend): JUG WIP e7d4298 HEAD@{1}: commit: JUG WIP 71ab831 HEAD@{2}: checkout: moving from gh-pages to jug 71ab831 HEAD@{3}: commit: Support more than one fade 76cd1b0 HEAD@{4}: commit: Tabs -> spaces $ git fsck --unreachable | grep commit unreachable commit 60c5758f209c63e5cc2d00f4c8e3ab8fc7037609 unreachable commit 6bc882d6491597250a2baa880e19f0759e1f585b unreachable commit 74cfdec6a9ba5b3e70c7bd1128fc3347440539b8 unreachable commit b76bb1f752afaaedc1b21d35c75c3acdce3d46e5
$ git commit --amend -m 'C was bad'
$ git reset --hard B # Like a pro: $ git reset --hard HEAD~
$ git revert [--no-commit] B
$ git filter-branch --subdirectory-filter src/lib -- --all
$ git filter-branch --index-filter 'git rm secret.txt' HEAD
svn:externals
(there be 🐉)
$ git svn-clone-externals svn://…
$ git checkoutswitch topic $ git rebase master
Commits C
, D
and E
are copied on top of master
as C'
, D'
and E'
.
How to get rid of C
when rebasing client
on master
?
$ git rebase --onto master server client
$ git rebase --onto B server client
$ git rebase origin/master pic.twitter.com/pAHtrPrm84
—
Alejandro AR (@kinduff)
January 16, 2015
git rebase -i ;) pic.twitter.com/Qy2k7Q0EQJ
—
nixCraft (@nixcraft)
May 7, 2017
$ git rebase --interactive A
Your options:
Visualizing a "Git Merge" pic.twitter.com/RQJ2AV7JRQ
— David Rousset (@davrous) August 20, 2016
$ git checkoutswitch master $ git merge topic
Recursive merge (~ ORT merge since git 2.34): Integrates two diverged branches.
$ git reset --hard F # Like a pro (covers recursive and ff merges): $ git reset --hard @@{1}
$ git checkoutswitch master $ git merge topic
Fast-forward merge: The master
pointer can be moved from C
to E
without losing commits reachable from master
.
git merge
behavior$ git merge --ff-only
Enforces a fast-forward merge, aborts if history is diverged.
$ git merge --no-ff
Enforces a recursive merge, even if a fast-forward merge would be possible.
git merge
recursive strategy$ git merge --strategy-option ours
Prefer our changes when encountering conflicts.
$ git merge -X theirs
Prefer their changes when encountering conflicts.
$ git merge --squash [--commit] topic
Merge HEAD
's and topic
's snapshot, create a new commit, but only assign HEAD
as its parent.
$ git merge perf css report
Integrate any number of non-conflicting branches with a single merge commit.
$ git cherry-pick [--no-commit] D
Apply a commit from somewhere else.
obsolete
's commits reachable, but keep tree as-is
obsolete
)
$ git merge --strategy=ours obsolete
release
's tree
$ git commit-tree release^{tree} -m "Merge branch 'release'" -p HEAD -p release
git merge
if you want to keep information about integrated branchesgit rebase
if you do not care$ git config --global alias.pfusch 'push -f'
May the 4th be with you 😁
pic.twitter.com/TnOUaGeoyU
— Jen Gentleman 🌺 (@JenMsft)
May 4, 2018
Server (9418/tcp)
$ git daemon --base-path=. --export-all --verbose [4242] Ready to rumble
Client
$ git clone git://host/relative/path/to/repo/.git foo Cloning into 'foo'...
$ git remote add hans git://host/relative/path/to/repo/.git $ git fetch hans remote: Counting objects: 42, done. … From git://host/relative/path/to/repo/.git e3205a5..0282413 master -> hans/master
pu
branchespu
git config --global rerere.enabled true git config --global rerere.autoUpdate true
# All branches were tested in isolation
$ git checkout -bswitch -c pu master
$ for b in perf css report; do git merge $b; done
$ git reset --hard master
$ for b in css report; do git merge $b; done
$ git checkoutswitch master; git merge pu; git branch -d pu
HEAD
state while searchinggit revert [--no-commit] <bad-commit>
git bisect run <some-script>
some-script
can do things like cherry-pick
ing reproductions, demo availablev1.0
works but v1.1
contains a regression$ git stash push -m "whatever you're doing"
$ git bisect start v1.1 v1.0
D
$ make test # => error
D
$ git bisect bad
B
$ make test # => success
B
$ git bisect good
C
$ make test # => success
C
$ git bisect good
# D is the first bad revision
$ git bisect reset
bisect
and cherry-pick
$ git checkout -bswitch -c repro v1.1 && git commit -m 'repro'
$ git bisect start v1.1 v1.0
repro
commit$ git cherry-pick repro
D
+ R'
$ make test # => error
R'
$ git reset --hard HEAD~
D
$ git bisect bad
$ git cherry-pick repro
git-rebase - Forward-port local commits to the updated upstream head
Show a printable version of this presentation. Use your browser to print.