Git Back to Basics CodeMash 2020

Git Back to Basics CodeMash 2020

Have you written code that worked, then broke it, only to not remember what the working code was?
Git, a version control application could be the solution you are looking for. Git can help you to track changes in your projects, go back to when your code is working, or even find out where it broke. You can use it in collaboration with a team or as the only developer on a project.
Learn the commands that are used every day as well as a few that can help you recover from mistakes.

Bdd05427e3fb1d1b0abc3cd081f81c6f?s=128

Angel Thomas

January 10, 2020
Tweet

Transcript

  1. GIT BACK TO BASICS Angel Thomas @starangel75

  2. ABOUT ME Angel Thomas Software Developer 
 Center for Information

    Management @starangel75
 https://speakerdeck.com/astahre/git-back-to-basics-codemash-2020
  3. ?

  4. WHAT IS GIT? Git is a Distributed Version Control System

  5. WHAT IS VERSION CONTROL? Any system that records changes over

    time
  6. TYPES OF VERSION CONTROL Old School: We just saved another

    copy with a slightly different name
  7. None
  8. TYPES OF VERSION CONTROL Centralized: There is one central copy

    of the project
  9. None
  10. TYPES OF VERSION CONTROL Decentralized: Each contributor has the project

  11. None
  12. GIT VOCABULARY Repository: a central location in which data is

    stored and managed
  13. GIT VOCABULARY Repository: a central location in which data is

    stored and managed Fork: a copy of a repository on a remote server
  14. GIT VOCABULARY Repository: a central location in which data is

    stored and managed Fork: a copy of a repository on a remote server Clone: a local copy of a repository
  15. INIT git init Creates a new git repository. This can

    be an empty project or to convert an existing project.
  16. CONFIG git config Set configurations for git

  17. CONFIG git config --global --edit Edit the git configuration file.

    These changes will be made in the default editor
  18. CONFIG git config --global user.name “Angel Thomas” git config --global

    user.email angel@xy.org Set identity information for configuration file without opening the editor
  19. CONFIG git config --list Check configuration settings

  20. CONFIG git config --global core.editor emacs git config --global core.editor

    vim Set preferred editor
  21. CLONE git clone hosting-service.com/username/repository-name (this can be ssh or https)

    Download a copy of a repository and create a local copy
  22. BRANCH git branch List branches in the current repository and

    indicate what branch is active
  23. BRANCH git branch newBranch Create a new branch

  24. BRANCH git branch feature/newBranch Create a new feature branch

  25. CHECKOUT git checkout <branch> Switch to a branch

  26. CHECKOUT git checkout -b <branch> Create a branch and switch

    to it
  27. NEW IN GIT 2.23 git switch <branch> Switch branches. This

    would replace checkout. * This is experimental and may change
  28. CONFIG . . AGAIN git config --global alias.co checkout git

    config --global alias.br branch git config --global alias.st status Set some aliases
  29. FETCH git fetch <remote> <branch> Fetch any commits that are

    on the remote repository that are not in the local repository
  30. MERGE git merge <branch> Merge commits that have been fetched

    or merge in another branch
  31. PULL git pull <remote> <branch> Combination of fetch and merge

  32. None
  33. STATUS git status Check the status of the local repository

  34. DIFF git diff Display changes that have not yet been

    staged
  35. ADD git add <filename> Add a file to the staging

    area
  36. ADD git add . Add all files to the staging

    area
  37. COMMIT git commit -m “commit message” Commit all changes

  38. COMMIT git commit --amend no-edit Any file changes made will

    be added to the commit without changing the commit message
  39. COMMIT git commit --amend -m “commit message” Change the commit.

    This would include file changes and change it to the new commit message.
  40. PUSH git push Push changes from local repository to remote

  41. PUSH git push -- force Push changes from local repository

    to remote removing commits that are on the remote that do not exist on the local
  42. PUSH git push -- force-with-lease Push changes from local repository

    to remote removing your commits that are on the remote that do not exist on the local, but failing if there are commits by others
  43. None
  44. REMOTE git remote List remotes

  45. PULL REQUEST Submit changes to be merged into the primary

    repository.
  46. None
  47. None
  48. LOG git log List the log of commits

  49. DIFF git diff <sha> <sha> Display changes between two commits

  50. RESET git reset Discards changes, but changes are still available

  51. RESET git reset <sha> Discards changes after specified commit, but

    changes are still available
  52. RESET git reset --hard Discards all history/changes that have not

    been committed
  53. NEW IN GIT 2.23 git restore <file> Discard changes made

    to the file * This is experimental and may change
  54. REFLOG git reflog Show what is recorded in the reflog

  55. STASH git stash Temporarily save changes made

  56. STASH git stash list Show a list of stashed file

    changes
  57. STASH git stash pop Apply changes from the top item

    in the stash list to the current branch
  58. CLEAN git clean -n Show which files would be removed

    from the working directory
  59. CLEAN git clean -f Remove files from the working directory

  60. MERGE CONFLICTS A merge conflict occurs when git is unable

    to automatically resolve the difference in changes between two or more commits.
  61. MERGE CONFLICTS Mergetools Kdiff3 P4Merge Beyond Compare DiffMerge Semantic Merge

  62. REVERT git revert A commit that reverses the work in

    the last commit
  63. REVERT git revert <sha> A commit that reverses the work

    done in the specified commit
  64. RESET git reset --hard <sha> Discards all history/changes after specified

    commit
  65. REBASE git rebase <remote>/<branch> Apply commits from the current branch

    to follow the commits of the remote branch
  66. REBASE git rebase <branch> Apply commits from the current branch

    to follow the commits of the specified local branch
  67. REBASE git rebase <sha> Apply commits from the current branch

    to follow the specified commit
  68. REBASE git rebase -i <sha> Opens in interactive window with

    all commits from the specified to the most recent
  69. REBASE git rebase -i HEAD~5 Opens in interactive window with

    the 5 most recent commits
  70. SQUASH git merge --squash <branch> Convert the commits of a

    specified branch into a single commit and merge it into the current branch
  71. CHERRY-PICK git cherry-pick <sha> Apply commit from another branch to

    the current branch
  72. BISECT git bisect start Start a bisect

  73. BISECT git bisect good <sha> Indicate that a commit is

    good
  74. BISECT git bisect bad <sha> Indicate that a commit is

    bad * Can also use old/new
  75. RESOURCES https://git-scm.com/doc
 https://www.atlassian.com/git/tutorials/atlassian-git- cheatsheet https://education.github.com/git-cheat-sheet-education.pdf https://about.gitlab.com/images/press/git-cheat-sheet.pdf http://gitimmersion.com/