On Github willdurand-slides / git-and-github-and-open-source
Hi! I'm Will, the author of this slide deck.
This slide does not exist in the original deck, but it is useful if you arenot familiar with Reveal.JS, the framework I used to write those slides.
The easiest way to navigate is by hitting [space]on your keyboard. You can also navigate with arrowkeys, but be careful because some slides can benested inside of each other (vertically).
You can also find this deck on Speaker Deck:
Why Open Source misses the point of Free Software (according to Richard Stallman)
Git is a widely used version control system for software development. It is a distributed revision control system.
Credit: https://aht.github.io/whatisgit/
git checkout <other-branch> -- /path/to/file
That's not what you want! No. Really.
git pull --rebase <remote> <branch>
git pull --rebase=preserve orpull.rebase=preserve (config)
git config --global help.autocorrect 1
git lol WARNING: You called a Git command named 'lol', which does not exist. Continuing under the assumption that you meant 'log' in 0.1 seconds automatically... commit 2feb149c8e76d12848f7535a8eb4d51b1c225776 Author: William Durand <will+git@drnd.me> Date: Mon Nov 16 14:54:53 2015 +0100 add badges ...
git co<tab><tab> commit config
git archive --format zip -o snapshot.zip HEAD
"Export" all files from a given commit into a directory:
git archive --format tar --prefix myapp/ <commit> | (cd /tmp && tar xf -)
git config --global rerere.enabled true
git merge master Auto-merging index.html CONFLICT (content): Merge conflict in index.html Recorded preimage for 'index.html' Automatic merge failed; fix conflicts and then commit the result.
git commit --no-edit Recorded resolution for 'index.html' [old-branch abcd123] Merge branch 'master' into old-branch
git merge master Auto-merging index.html CONFLICT (content): Merge conflict in index.html Resolved 'index.html' using previous resolution.
Performs a binary search across a range of commits to help you find where an error was introduced:
git bisect start
git bisect good abcd123
git bisect bad [badd123]
# The script should end with a non-zero return status when it fails git bisect run mvn clean test
Quickly save current state:
git stash -u 'current state'
Restore it, later:
git stash apply
Or git stash pop but I rarely use it...
git rebase -i HEAD~<number of commits>
pick d1ed4e4 Fix typo pick b49cb42 Update for lavajug pick e35510f Add new images # Rebase 5f167bb..e35510f onto 5f167bb (3 command(s)) # # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = like "squash", but discard this commit's log message # x, exec = run command (the rest of the line) using shell # # These lines can be re-ordered; they are executed from top to bottom. # # If you remove a line here THAT COMMIT WILL BE LOST. # # However, if you remove everything, the rebase will be aborted. # # Note that empty commits are commented out
git pull --rebase origin master
git add -p
diff --git a/test.js b/test.js index 60ac996..2a57310 100644 --- a/test.js +++ b/test.js @@ -1,6 +1,5 @@ (function () { - var i, j; + var i = 0, j; - i = 0; - j = i; + j = 1; })(); Stage this hunk [y,n,q,a,d,/,s,e,?]? s Split into 2 hunks. @@ -1,3 +1,3 @@ (function () { - var i, j; + var i = 0, j; Stage this hunk [y,n,q,a,d,/,j,J,g,e,?]?
git commit --amend
git commit --amend -m 'Fix undefined variable j Fix #123'
git checkout - Switched to branch 'master'
git checkout - Switched to branch 'feat-undefined-variable'
Also works with merge, cherry-pick and rebase.
git branch --no-merged develop feat-another-feature feat-my-feature fix-undefined-variable
git branch --merged * master
git format-patch master --stdout > fix-undefined-variable.patch
From: William Durand <will+git@drnd.me> Date: Thu, 13 Nov 2015 10:22:17 +0100 Subject: [PATCH] Fix undefined variable --- test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.js b/test.js index 760e4eb..60ac996 100644 --- a/test.js +++ b/test.js @@ -1,5 +1,5 @@ (function () { - var i; + var i, j; i = 0; j = i; -- 2.1.2
git apply --stat fix-undefined-variable.patch
test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
git apply --check fix-undefined-variable.patch
No output ==
git am --signoff < fix-undefined-variable.patch
Applying: Fix undefined variable
commit 4c20f8d517b99638f5379f3f0894ad076d2b6a5b Author: William Durand <will+git@drnd.me> Date: Thu Nov 13 10:22:17 2015 +0100 Fix undefined variable Signed-off-by: William Durand <will+git@drnd.me>
BTW, patch -p1 works too!
GitHub is the largest code host on the planetwith over 29.5 million repositories.
Pull Request = Code + Issue + Code Comments
Also, checkout 5minfork.com!
https://github.com/your/repo/commit/e0af340837978f80d8cd144a4475.patch
curl https://github.com/your/repo/commit/<SHA>.patch |git am Applying: Fix undefined variable
https://github.com/your/repo/commit/e0af340837978f80d8cd144a4475.diff
git + hub = github
alias git=hub
git clone random/repo # git clone git://github.com/random/repo.git
git clone repo # git clone git://github.com/YOUR/repo.git
git browse # open https://github.com/random/repo
git browse -- issues # open https://github.com/random/repo/issues
git fetch ubermuda # git remote add ubermuda git://github.com/ubermuda/repo.git # git fetch ubermuda
git checkout https://github.com/your/repo/pull/123 # git remote add contributor git://github.com/contributor/repo.git # git fetch contributor # git checkout -b contributor-branch contributor/branch
Best way to [work on|review|test] a Pull Request so far!
git am -3 https://github.com/your/repo/pull/123
git cherry-pick https://github.com/random/repo/commit/SHA # git remote random git://github.com/random/repo.git # git fetch random # git cherry-pick SHA
git fork, git pull-request, merge, ci-status, etc.
GitLab is an Open Source (MIT licensed) web-based Git repository manager with wiki and issue tracking features.
GitLab started a side project in 2011.
In 2015, more than 800 (worldwide) contributors, 10+ employees, and 1.5M raised in seed funding in July.
Pro-tip: Merge Request ≈ Pull Request
"A successful Git branching model"
Well... Maybe not. See this simplegit branching model instead.
👍 + 👍 = Good to merge/ship
In production and development, Open Source as a development model promotes a universal access via a free license to a product's design or blueprint [...].
Open-source software is very often developedin a public, collaborative manner.
Everyone can contribute.
git checkout -b feature-branch
But, how?
(If it does not exist, contribute by adding it!)
Capitalized, short (50 chars or less) summary More detailed explanatory text, if necessary. Wrap it to about 72 characters or so. In some contexts, the first line is treated as the subject of an email and the rest of the text as the body. The blank line separating the summary from the body is critical (unless you omit the body entirely); tools like rebase can get confused if you run the two together. Write your commit message in the imperative: "Fix bug" and not "Fixed bug" or "Fixes bug." This convention matches up with commit messages generated by commands like git merge and git revert. Further paragraphs come after blank lines.
"Subject of an email"
Emojis all the things! (like Atom)
(Blank line before details)
"Body of an email"
GitHub Flavored Markdown (GFM):
git rebase -i HEAD~2
pick 5335450 add test pick 4c20f8d Fix undefined variable # Rebase 35124cb..4c20f8d onto 35124cb # # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = like "squash", but discard this commit's log message # x, exec = run command (the rest of the line) using shell # # These lines can be re-ordered; they are executed from top to bottom. # # If you remove a line here THAT COMMIT WILL BE LOST. # # However, if you remove everything, the rebase will be aborted. # # Note that empty commits are commented out
An Open Source maintainer will look at your work.
http://www.gousios.gr/blog/How-do-project-owners-use-pull-requests-on-Github/
project-x ========= project-x is a better way to achieve this and that, by leveraging the new API, bla bla bla. ## Usage ... ## Installation ... ## Requirements ... ## Contributing See CONTRIBUTING file.
README example 1/2
## Running the Tests ... ## Credits ... ## Contributor Code of Conduct Please note that this project is released with a [Contributor Code of Conduct](http://contributor-covenant.org/). By participating in this project you agree to abide by its terms. See CODE_OF_CONDUCT file. ## License project-x is released under the MIT License. See the bundled LICENSE file for details.
README example 2/2
Also, checkout Atom's one!
MAJOR.MINOR.PATCH
A change log is a file which contains a curated, ordered list of notable changes for each version of a project.
Source: https://plus.google.com/+LennartPoetteringTheOneAndOnly/posts/J2TZrTvu7vd
Open Source is more thanmaking code available for free.
It is a lot of work!
Care about the people first.
Communication is essential!
Everyone can contribute!
Open Source is more thandownloading code available for free.
Give, don't (only) take.
There are people behind Open Source projects.
Money is still an issue in OSS.