Skip to content

Latest commit

 

History

History
94 lines (63 loc) · 6.33 KB

guide.md

File metadata and controls

94 lines (63 loc) · 6.33 KB

Becoming proficient with Git

Best practices

  • This is the mother of all informative resources about Git. Read it very carefully.
  • There is also a good web-app which helps you learn the behavior of git: https://learngitbranching.js.org/

A Git repository is a directed acyclic graph (DAG) of commits

  • The commit DAG is frequently reported to be "the most important thing to realize about git". You should strive to understand every git command in terms of how it manipulates the commit graph! The VGR is an excellent resource to understand this.
  • Have a look at the DAG of your repository with git log --all --decorate --oneline --graph (log adog / "look, a dog!")
  • What you need to internalize is that commits are nodes in a DAG. All commits have one parent commit, merge commits have two parents.
  • Another concept you need to understand are references. Branches, tags and HEAD are all references. Which basically means they are an alias of a particular commit.
  • Examples: "mergecreates a commit with two parent commits", "cherry-pick takes a list of commit hashes and applies them as patches onto HEAD" and "reset takes a reference to or the hash of a commit and makes the current branch point to it".
  • HEAD is a special reference.
  • Relative references, like HEAD~2 are very helpful too.

Rebasing

  • Rebasing is an alternative to merging in as far as both of them are ways to integrate two branches. A rebase is a special case of cherry-pick.

cherry-pick

  • Select commits by their hashes and apply them one-by-one onto HEAD
  • See the VGR for visual aid.

rebase

  • Rebase does the same as cherry-pick, only for entire branches automatically. The VGR explains the technical side of rebases pretty well.
  • This guide -- Getting solid at Git rebase vs. merge -- explains in depth the pros and cons of rebase and merge. It's a very long post and many of its contents will also be covered in this guide. However, you should definitely add this to your read-later list.

push --force / push --force-with-lease

  • After you rebased a branch it contains different commits than before. Because of that git push will reject your changes.
  • A full explanation of the problem and why --force-with-lease is a better solution than --force can be found here.

Working with remotes

  • Learn about tracking upstream branches. This link covers git push --set-upstream aka git push -u.
    • git branch -vva will give you an overview of which remote branches your local branches track

How to pull correctly

  • Before turning to pull, let's make clear what a fast-forward merge is.

  • Fast-forward merges

  • pull vs pull --rebase vs pull --ff-only

Workflow

On the importance of worrying about your commit history