12. .gitignore
• What?
– Makes git ignore files / directories
– Repo specific or global
– Drupal example of a .gitignore file:
http://drupalcode.org/project/drupal.git/blob/HEAD:
/example.gitignore
13. .gitignore
# Ignore configuration files that may contain sensitive information
*/sites/*/settings*.php
# Ignore paths that contain user-generated content.
*/sites/*files
*/sites/*/private
# Ignore editor specific files
Drupal.sublime-projectcompletions
*.sublime-project
*.sublime-workspace
# Ignore OS specific files
.DS_Store
14. global .gitignore
• Create any file:
- $vi ~/.gitignore_global
• Add paths to be ignored.
- Example: https://gist.github.com/4321950
• Use as global gitignore file:
Git config –global core.excludesfile
~/.gitignore_global
15. local .gitignore
• Create a .gitignore file:
- $vi ~/your_project/.gitignore
• Place it anywhere in your repo
• Add paths to be ignored, relative to the location of
the file.
37. A basic workflow
Git commit
• Changes are committed to local repo
• Others won‟t see these changes yet
• Commit message is required
• And should look like „Issue #123: describe what
you changed.‟
44. A basic workflow
• Remote branch contains commit(s) that are not
present in your local branch.
• Get those commits first by merging, then push your
commits.
67. Git checkout
• Throw away changes: $ git checkout index.html
• Restores your working tree to the last version
committed to git.
• Use git checkout to throw away changes that have
not been added and committed.
• Use carefully.
71. Git reset
• Keep your code changes, remove file from
the index: $ git reset HEAD index.html
• Restores your index to the last version
known to git.
74. Git reset --hard
• Resets working tree and index to a specific
commit.
• $ git reset --hard 5497461
• Reset a branch to the origin branch: $ git
reset --hard origin/master
• Use carefully.
81. Branching
- Create a new branch: $ git branch issue-123
- Switch to that branch: $ git checkout issue123
- Or create and switch to a branch: $ git
checkout -b issue-123
- Push branch to origin: $ git push origin
issue-123
82. Branching
- Use a remote branch: $ git checkout -t
origin/issue-11699
83. Branching
• Delete a local branch that is fully merged: $
git branch -d branch_name
• Force delete a local branch: $ git branch -D
branch_name
• Delete a remote branch: $ git push origin -delete :branch_name
• Completely remove a branch: $ git push
origin --delete :branch_name $ git branch -D
branch_name
88. Patching
• $ git diff > [project_name][short_description]-[issue-number][comment-number].patch
• Add the patch file to the root of the module
you patched.
91. Git stash
• Store code changes without committing
them.
• Handy when you urgently need to switch
branches.
• Stash your code changes: $ git stash
• List all available stashes: $ git stash list
• Most recent stash is shown on top
99. Git bisect
• Find out in when something broke
• First, find a commit when everything was
working
• Find a commit where things are not working.
• Go to the root of the repository
• $ git bisect start $ git bisect good fd0a623 $
git bisect bad 256d85
100. Git bisect
• Refresh the page and see if the bug is there
• $ git bisect good/git bisect bad
• Repeat until git tells you the commit that
broke it