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.

66658347c90b0d70e175e54949d3ff93?s=128

Rachell Calhoun

July 20, 2016
Tweet

Transcript

  1. Version Control and How it Can Save Your Life @Rachell_Calhoun

    Git in Control DjangoCon US 2016
  2. Git in Control 1. $whoami 2. Version control 3. Setting

    up Git 4. Basic Commands 5. Tricky Stuff 6. Gitiquette
  3. $whoami git config -- global user.name "Rachell Calhoun" Git config

    $whoami
  4. Rachell ( yes, with 2 Ls)

  5. Git in Control 1. $whoami 2. Version control 3. Setting

    up Git 4. Basic Commands 5. Tricky Stuff 6. Gitiquette
  6. Version control?

  7. Solo Projects

  8. Collaborating

  9. Git in Control 1. $whoami 2. Version control 3. Setting

    up Git 4. Basic Commands 5. Tricky Stuff 6. Gitiquette
  10. git config --global user.name "Jane Doe" git config --global user.email

    janedoe@example.com
  11. $ git init $ git remote add origin path/to/origin

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

  13. Workflow Init/Clone

  14. Git in Control 1. $whoami 2. Version control 3. Setting

    up Git 4. Basic Commands 5. Tricky Stuff 6. Gitiquette
  15. $ git status

  16. $ git status On branch branchname Untracked files: (use "git

    add <file>..." to include in what will be committed) list_of_passwords passwords2 nothing added to commit but untracked files present (use "git add" to track)
  17. $ git add path/to/filename

  18. $ git add filename

  19. $ git add --all

  20. Workflow Init/Clone > Add

  21. $ git commit

  22. $ git commit -m “...” git commit -m ”I made

    some awesome changes”.
  23. Workflow Init/Clone > Add > Commit C1

  24. $ git push

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

    push origin branchname
  26. Sum it up Init/Clone > Add > Commit > Push

    C1 C1
  27. Branches

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

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

  30. $ git branch -d work-branch Master

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

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

  33. None
  34. $ git fetch origin

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

    W2 W1 W2 P1 P2
  36. Conflicts

  37. git pull = fetch + merge

  38. Forking

  39. Pull Request

  40. Celebrate!

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

  42. $ git pull upstream master

  43. Git in Control 1. $whoami 2. Version control 3. Setting

    up Git 4. Basic Commands 5. Tricky Stuff 6. Gitiquette
  44. Tricky stuff

  45. $ git stash

  46. $ git stash -u

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

    git stash pop
  48. $ git stash branch party-branch

  49. Undo Local Commits

  50. Undo local commits $ git reset HEAD~2 $ git reset

    --hard HEAD~2 $ git reset --hard 234jk3
  51. $ git rm list_of_passwords Removing files

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

    >> .gitignore
  53. None
  54. None
  55. Edit a Commit Message $ git commit --amend $ git

    commit --amend -m "New message that sounds like I know what I’m doing!"
  56. Add a Forgotten File $ git add forgotten_file $ git

    commit --amend $ git diff --stat --cached origin/master
  57. Git in Control 1. $whoami 2. Version control 3. Setting

    up Git 4. Basic Commands 5. Tricky Stuff 6. Gitiquette
  58. Gidiquette - Check issues - Branch naming - Keep changes

    small - Respect the coding style - Play nice with others
  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
  60. Thank You! @Rachell_Calhoun