Meet Git

Git is awesome !

Created by Baptiste Leduc for Weglot

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 details:

name, author, date, description

Remote

It store, for each branch, the last commit you pushed to them.

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
					

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 --pretty=format:"%h %s" --graph

Usefull 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

Links