Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Git in Control, Version Control and How it Can Save Your Life

Git in Control, Version Control and How it Can Save Your Life

“You can’t break GitHub, don’t worry.” Maybe you can’t break it but you can sure get yourself into a labyrinth of git commands. Version control can be a headache but it can also save your project.

There are certain pitfalls to avoid when using Git, I’ve probably found most of them and stumbled my way out. While my goal is to help you avoid them altogether, I also want to give you the skills to work through these pitfalls so you can make it out alive and with your project intact.

Whether you’re working on your own project, or collaborating with others you can learn how to git survive anything. We’ll discuss the benefits version control has for your own projects as well as projects with others.

For all of you awesome collaborators working with others on a project, we’ll go over important steps to take while handling others’ code and ‘gitiquette’ so you can save yourself the embarrassment of faux pas in the git world.

This will give you an overview of Github flow, provide solutions for potential problems you may encounter, and help you feel more comfortable with version control.

Rachell Calhoun

July 20, 2016
Tweet

More Decks by Rachell Calhoun

Other Decks in Technology

Transcript

  1. Version Control and How it
    Can Save Your Life
    @Rachell_Calhoun
    Git in
    Control
    DjangoCon US 2016

    View Slide

  2. Git in Control
    1. $whoami
    2. Version control
    3. Setting up Git
    4. Basic Commands
    5. Tricky Stuff
    6. Gitiquette

    View Slide

  3. $whoami
    git config --
    global user.name
    "Rachell Calhoun"
    Git config
    $whoami

    View Slide

  4. Rachell ( yes, with 2 Ls)

    View Slide

  5. Git in Control
    1. $whoami
    2. Version control
    3. Setting up Git
    4. Basic Commands
    5. Tricky Stuff
    6. Gitiquette

    View Slide

  6. Version control?

    View Slide

  7. Solo Projects

    View Slide

  8. Collaborating

    View Slide

  9. Git in Control
    1. $whoami
    2. Version control
    3. Setting up Git
    4. Basic Commands
    5. Tricky Stuff
    6. Gitiquette

    View Slide

  10. git config --global user.name
    "Jane Doe"
    git config --global user.email
    [email protected]

    View Slide

  11. $ git init
    $ git remote add origin
    path/to/origin

    View Slide

  12. $git clone path/to/remote/repo

    View Slide

  13. Workflow
    Init/Clone

    View Slide

  14. Git in Control
    1. $whoami
    2. Version control
    3. Setting up Git
    4. Basic Commands
    5. Tricky Stuff
    6. Gitiquette

    View Slide

  15. $ git status

    View Slide

  16. $ git status
    On branch branchname
    Untracked files:
    (use "git add ..." to include in what will
    be committed)
    list_of_passwords
    passwords2
    nothing added to commit but untracked files
    present (use "git add" to track)

    View Slide

  17. $ git add path/to/filename

    View Slide

  18. $ git add filename

    View Slide

  19. $ git add --all

    View Slide

  20. Workflow
    Init/Clone > Add

    View Slide

  21. $ git commit

    View Slide

  22. $ git commit -m “...”
    git commit -m ”I made
    some awesome
    changes”.

    View Slide

  23. Workflow
    Init/Clone > Add > Commit
    C1

    View Slide

  24. $ git push

    View Slide

  25. $ git push
    $ git push origin master
    $ git push origin branchname

    View Slide

  26. Sum it up
    Init/Clone > Add > Commit > Push
    C1 C1

    View Slide

  27. Branches

    View Slide

  28. Branches
    Master
    work-branch
    party-branch P1 P2
    W1 W2

    View Slide

  29. $ git checkout -b work-branch
    Master
    work-branch

    View Slide

  30. $ git branch -d work-branch
    Master

    View Slide

  31. $ git push origin work-branch
    Origin
    work-branch W1 W2
    Push
    Master
    work-branch

    View Slide

  32. $ git branch
    master
    work-branch
    * party-branch

    View Slide

  33. View Slide

  34. $ git fetch origin

    View Slide

  35. $ git merge work-branch
    Master
    work-branch
    party-branch P1 P2
    W1 W2
    W1
    W2
    P1
    P2

    View Slide

  36. Conflicts

    View Slide

  37. git pull = fetch + merge

    View Slide

  38. Forking

    View Slide

  39. Pull Request

    View Slide

  40. Celebrate!

    View Slide

  41. $ git remote add upstream
    path/to/original/repo

    View Slide

  42. $ git pull upstream master

    View Slide

  43. Git in Control
    1. $whoami
    2. Version control
    3. Setting up Git
    4. Basic Commands
    5. Tricky Stuff
    6. Gitiquette

    View Slide

  44. Tricky stuff

    View Slide

  45. $ git stash

    View Slide

  46. $ git stash -u

    View Slide

  47. Stash
    $ git stash apply
    $ git stash drop
    $ git stash pop

    View Slide

  48. $ git stash branch
    party-branch

    View Slide

  49. Undo Local Commits

    View Slide

  50. Undo local commits
    $ git reset HEAD~2
    $ git reset --hard HEAD~2
    $ git reset --hard 234jk3

    View Slide

  51. $ git rm list_of_passwords
    Removing files

    View Slide

  52. Removing (added) files
    $ git reset list_of_passwords
    $ echo list_of_passwords >>
    .gitignore

    View Slide

  53. View Slide

  54. View Slide

  55. Edit a Commit Message
    $ git commit --amend
    $ git commit --amend -m
    "New message that sounds
    like I know what I’m doing!"

    View Slide

  56. Add a Forgotten File
    $ git add forgotten_file
    $ git commit --amend
    $ git diff --stat --cached
    origin/master

    View Slide

  57. Git in Control
    1. $whoami
    2. Version control
    3. Setting up Git
    4. Basic Commands
    5. Tricky Stuff
    6. Gitiquette

    View Slide

  58. Gidiquette
    - Check issues
    - Branch naming
    - Keep changes small
    - Respect the coding style
    - Play nice with others

    View Slide

  59. To Summarize:
    git config --global user.name
    git config --global user.email
    git init
    git remote add origin
    git clone
    git status
    git add
    git commit -m “...”
    git push
    git checkout -b branchname
    git branch -d branchname
    git push origin branchname
    git branch
    git fetch origin
    git merge branchname
    git pull
    Forking
    Compare and Pull Request
    git remote add upstream path/to/rep
    Git pull upstream master
    git stash
    git stash -u
    git stash apply
    git stash drop
    git stash pop
    git stash branch branchname
    git reset HEAD~2
    git reset --hard HEAD~2
    git reset --hard 234jk3
    git rm list_of_passwords
    git reset list_of_passwords
    git commit --amend -m “...”
    git add forgotten_file
    git diff --stat --cached origin/master

    View Slide

  60. Thank You!
    @Rachell_Calhoun

    View Slide