Daniele Scasciafratte - Nome Evento

Git in 30 minutes

Handy tips for your daily fight with Git

Created by Daniele Scasciafratte / @Mte90net

Daniele Scasciafratte

  • Co Founder/CTO Codeat
  • Italian Linux Society Council member
  • LUG Rieti founder
  • WordPress Core Contributor/Developer
  • WordPress Rome/Terni meetup
  • Mozillian & Mozilla Reps & Mozilla Italia
  • Open Source Addicted


Or you were following another talk instead of this.

Git Network Schema

  • Pull means download the latest changes of a branch
  • Push means upload the latest changes of a branch
  • Fetch means download all the changes in all the branch of the repository

Git explained like I am 5 years old

  • A fork is a remote copy of a repository
  • A branch is a mechanism to create different versions of the same repository that you can merge
  • A pull request/merge request (PR/MR) is a merge request of a specific branch (usually not the master/main) of the same repository or another one
  • A conflict happens when your copy is not aligned or changed in a way that git cannot merge it
  • Fast forward is an issue about a missing identification of your last commit during a merge

Git gui

There are Git Guis but I prefer the commandline as works always

Git 101

  • Create a branch (suggested for incomplete stuff)
  • Add files to git
  • Write a commit understable also after some time
  • Push on your server
  • Now it is more easy to do a pull request

Git Fork 101

Git Fork 101

  • Create a fork in the service you are using
  • Git clone tat repository
  • git remote add upstream https://original-repo
  • With git fetch --all you update everything
  • With git merge upstream/master you are merging the upstream repository in your fork
  • Now you can push it on your fork as updated

Git Merge/Rebase 101

Git diff/patch 101

                        git diff HEAD~6 > last-6-commits.diff
                        git range-diff 9dcf19459ffb8b02e8232eacdc6079a265517bed..f93aca03caba4edaf787e9751db54cf42d662180

Git reset/clean 101

                        git reset --hard HEAD~1
                        git reset --hard (upstream/master)
                        git stash

Git verbose 101

                        git branch -v
                        git remote -v

You need (bash) alias!

My alias

# For Git
alias git-commit-rename='git commit --amend'
alias git-remove-last-commit='git reset --soft HEAD~1'
#  To remember the SSH password for 36000 minutes
alias git-pass='ssh-add -t 36000'
alias gpm="git push origin master"
alias git-restage="git update-index --again"
alias git-rename-branch="git rename-branch"
alias git-remove-deleted-branch-remotely="git remote prune origin"
#  Add and remove new/deleted files from git index automatically
function git-merge-last-commits() { git reset --soft HEAD~$1 && git commit; }
function git-stat-months() { git diff --shortstat "@{$1 month ago}"; }


Conventional Commits!

                        feat(release): updated CI
                        refactor(engine): changed the sort order
                        fix(css): wrong padding for header


You need (bash) wrappers!




Git wrapper executed before and after the git commands.

					git clone https://github.com/mte90/project-forked --fork
					git checkout https://github.com/mte90/project-forked/pull/12


BFG Repo-Cleaner!

Remove files from a git repo once for all.

					java -jar bfg.jar --strip-blobs-bigger-than 100M some-big-repo.git
					bfg --delete-files id_{dsa,rsa}  my-repo.git


You need options!

GitHub and GitLab let you disable the force solution to specific branch. Enable it!