Fork me on GitHub

Introduction to git: Workshop 2 - summary

Overview

Teaching: 0 min
Exercises: 0 min
Objectives
  • reviewing key points of Git - workshop 2

What we have discussed so far:

  • Git workflow with branches - useful tips:

    • use branches to experiment and to work on things in parallel;
    • branch often
    • keep the master branch as clean as possible
    • use git branch or git status to make sure you are on the right branch
  • It is good to have a remote host for your repository:

    • use web services like GitHub, GitLab, etc.
  • It is a good practice (in most cases) to commit your work:

    • use stashes or branches to save your local changes

    • use git checkout only if you are absolutely sure you don’t need local changes

    • Git commits can be reverted:

      • use git revert <hash> to undo the commit - this creates a new commit
    • Git commits can be modified:

      • use git commit --amend to modify the last commit (this changes history!)
    • Git commits can be removed:

      • use git reset --hard <hash> to bring HEAD to <hash> and remove all later commits (this changes history!)
      • use git reset --hard @{u} to make the local branch identical to upstream (this changes history!)
    • Some Git commands rewrite history - try to avoid them on public commits