A bit of

Why git?

  • Distributed (no central server "really" needed)
  • Fast!
  • Cheap branch creation
  • Commits are local, so you can work off-line (without network connection) and submit your changes later
  • Great tool set, awesome community

The basics

Fetch

Uploads local changes to a remote repository

Pull

Do a fetch and incorporates changes from a remote repository into the current branch in your working copy

Push

Downloads all remote information to the local repo (branches, tags, etc.)

Clone

Like pull but also creates your local repository first.

File life cycle

Branch model

Remote

Commit pointer, "friendly" name to some point of the repo history (there are to types: lightweight and annotated).

Branch

History tree pointer (master was historically the default branch, now is configurable).

Tag

Reference to a repository (origin is the default one).

Reference to the branch you’re currently on.

HEAD

Meet the Merge

Join two or more development histories (usually branches) together

Fast Forward

Rebase

Reapply commits on top of another base (usually a branch) tip

Rebasing a feature

Rebasing a feature

Interactive rebase

Interactive rebasing lets you clean up history by reordering, removing, splitting, and altering an existing series of commits

Use case: squashing

Merge vs Rebase

Merging...

Rebasing...

Rewriting the history

Rebasing a branch rewrite its history, so the golden rule of git rebase is to never use it on public branches.

 

 

Is anyone else looking at this branch?

Example: rebasing master main (never do it!!!)

May the --force be with you...

Keeping in sync

git fetch

git pull

git merge

git rebase

Making changes

git add

git delete

git commit

Moving and looking around

git branch

git tag

git checkout switch (since v2.23.0)

What, Who, When?

git log

git show

git blame

git diff

Fixing and Undoing

git amend

git reset

git revert

Give me that code

git cherry-pick

git checkout restore (since v2.23.0)

Configuring git

settings that applies all repos beloging to an user

system

settings that applies to all users (computer level)

global

local

settings that applies to the repo

git config --global user.name "John Doe"

git config --global user.email johndoe@example.com

If you want to commit code...

git config --global pull.rebase true

 

git config --global push.default simple (default value since v2.0)

 

git config --global core.excludesfile ~/.gitignore_global

Pretty config settings

# Visual Studio Code
git config --global core.editor "code --wait"

# Atom
git config --global core.editor "atom --wait"

# Sublime Text
git config --global core.editor "subl -n -w"

If you don't like Vim 😞

Play time

> sudo applause

A bit of git

By Eduardo Bellido Bellido

A bit of git

Learn a bit of git

  • 1,358