Meet Git

Git is awesome !

Created by Baptiste Leduc for JoliCode

1. What is git ?

Git basics

  • Working: You modify files in your working tree.
  • Staging: You selectively stage just those changes you want to be part of your next commit.
  • Repository: You do a commit.

Your local git is a repository

Distant git is a repository (and you can have multiple distant git, for example when using forks)


Each repository have their own branches, you won't recover them by simply fetching a repository

References

A lot in theses !

HEAD

You always have a HEAD when on a branch

It contains a reference to the last commit of that branch

Tag

Points to a commit with some metadatas:

name, description

author & date are already embed with commits

2. Usage


git fetch

Pulling changes from distant remote for all branches. It's updating references for this remote & all related branches.

git pull

git pull

Correspond to:


						git fetch
						git merge FETCH_HEAD
					

git merge

git merge

When ?

To merge a final branch to a develop/master branch

git rebase

How to:


						git fetch [remote]
						git rebase [remote]/[branch]
					

git add

Adding one by one is ... borring !

Git add - Patch mode !

git add -p

Logs !

Ugly logs

git log

Pretty logs ?

Quite easy:

git log --graph --date=relative --pretty=tformat:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%an %ad)%Creset'

History logs !

git reflog is decoupled from HEAD and repository. It's just a local history of git.

git reflog

git reset

git reset --soft [...]

It will move HEAD location (last commit in branch) and keep changes.

git reset --hard [...]

Will move HEAD location and remove changes.

[...] what ?

Based on HEAD: "HEAD~..."

Based on commit: "c14809fa" (commit hash)

Examples:


							git reset --soft HEAD~0
							git reset --soft c14809fa
						

git commit

git commit -m "message"
git commit --amend

3. Tips


Aliases !

Status

git s
git st

...

Oops 🤫

git oops
git commit --amend --no-edit

Rebase

git rc
git rebase --continue

&

git rs
git rebase --skip

Logs ! 🎉

git lg
git log --graph --date=relative --pretty=tformat:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%an %ad)%Creset'

pull rebase 🐳


						[pull]
						rebase = preserve
					

rerere


						[rerere]
						enabled = true
					
git rerere [diff]

Things you should watch

  • core.editor
  • help.autocorrect
  • commit.gpgsign
  • ...

Links