{"id":17910527,"url":"https://github.com/matthieulemoine/git-training","last_synced_at":"2025-06-12T07:32:16.299Z","repository":{"id":89448348,"uuid":"82858841","full_name":"MatthieuLemoine/git-training","owner":"MatthieuLemoine","description":"Yet another git training.","archived":false,"fork":false,"pushed_at":"2017-02-23T11:24:29.000Z","size":306,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-03T10:23:45.943Z","etag":null,"topics":["git","slides","training"],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MatthieuLemoine.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-22T22:28:14.000Z","updated_at":"2017-10-20T15:47:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"33bb8e08-b644-4daf-8e06-1689bc4a2ee3","html_url":"https://github.com/MatthieuLemoine/git-training","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MatthieuLemoine/git-training","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatthieuLemoine%2Fgit-training","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatthieuLemoine%2Fgit-training/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatthieuLemoine%2Fgit-training/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatthieuLemoine%2Fgit-training/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MatthieuLemoine","download_url":"https://codeload.github.com/MatthieuLemoine/git-training/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatthieuLemoine%2Fgit-training/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259420535,"owners_count":22854602,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["git","slides","training"],"created_at":"2024-10-28T19:32:20.213Z","updated_at":"2025-06-12T07:32:16.280Z","avatar_url":"https://github.com/MatthieuLemoine.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Git\n## Advanced training\n\n:zap: Powered by [remarkjs](https://github.com/gnab/remark).\n\n---\n\n# Summary\n\n## I. Basics\n## II. HOWTOs\n## III. Git Flow\n## IV. Tips\n\n---\n\n# Basics\n\n- Distributed != Centralised\n\n![distributed](./assets/distributed.png)\n![centralised](./assets/centralised.png)\n\n- Basic commands\n\n```\n$ git init\n$ git status\n$ git add \u003cfilepath\u003e\n$ git commit -m \u003cmessage\u003e\n$ git push \u003cremote\u003e \u003cbranch\u003e\n```\n\n- Ignore files : **.gitignore**\n\n\n---\n\n# HOWTOs\n\n- How to setup git ?\n```\n$ git config --global user.name \u003cusername\u003e\n$ git config --global user.email \u003cemail\u003e\n```\n- How to choose my editor ?\n```\n$ git config --global core.editor vim\n```\n- How to generate a ssh key ?\n```\n$ ssh-keygen -t rsa -b 4096 -C \u003cemail\u003e\n```\n- How to add a remote repository ?\n```\n$ git remote add origin git@github.com:\u003cuser\u003e/\u003crepo\u003e.git\n```\n- How to change a remote repository url ?\n```\n$ git remote set-url origin git@github.com:\u003cuser\u003e/\u003crepo\u003e.git\n```\n\n---\n\n# HOWTOs\n\n- How to untrack a file without deleting it ?\n```\n$ echo \u003cfilename\u003e \u003e\u003e .gitignore\n$ git rm --cached \u003cfilename\u003e\n```\n- How to view my local changes ?\n```\n$ git diff\n```\n- How to view the commit list ?\n```\n$ git log --oneline --decorate --graph\n```\n- How to pull without having to commit ?\n```\n$ git stash\n$ git pull \u003cremote\u003e \u003cbranch\u003e\n$ git stash pop\n```\n\n---\n\n# HOWTOs\n\n- How to create a branch ?\n```\n$ git checkout -b \u003cbranch\u003e\n```\n- How to keep a file in the repository but disable change tracking ?\n```\n$ git update-index --assume-unchanged \u003cfilename\u003e\n```\n- How to reactivate change tracking ?\n```\n$ git update-index --no-assume-unchanged \u003cfilename\u003e\n```\n- How to edit my last commit ? (I forgot one file, I made a typo in the commit message)\n```\n$ git add \u003cfile\u003e\n$ git commit --amend\n# or if I don't want to change the commit message\n$ git commit --amend --no-edit\n```\n\n\n---\n\n# HOWTOs\n\n- How to undo my changes ?\n```\n$ git status\n# Before ``git add``\n$ git checkout -- \u003cfilename\u003e\n# After ``git add``\n$ git reset HEAD \u003cfilename\u003e\n$ git checkout -- \u003cfilename\u003e\n```\n- How to uncommit ?\n```\n# If I want to keep my changes\n$ git reset --soft HEAD~1\n# If I want to delete my changes\n$ git reset --hard HEAD~1\n# Then if I have already pushed to the remote repository\n# I may need to disable branch protection\n$ git push \u003cremote\u003e \u003cbranch\u003e -f\n```\n\n---\n\n# HOWTOs\n\n- How to merge a list of commit ?\n```\n$ git rebase -i HEAD~\u003cnumberOfCommits\u003e\npick 1b68a67 :bug: Fix #27\nsquash 6b36b82 :wrench: Replace config files with env variables.\nsquash 3da99cc :heavy_minus_sign: :heavy_plus_sign: Replace node-uuid by uuid\nsquash 5e6c751 :arrow_up: Upgrading dependencies\n# Rebase 479f697..5e6c751 onto 479f697 (4 command(s))\n#\n# Commands:\n# p, pick = use commit\n# r, reword = use commit, but edit the commit message\n# e, edit = use commit, but stop for amending\n# s, squash = use commit, but meld into previous commit\n# f, fixup = like \"squash\", but discard this commit's log message\n# x, exec = run command (the rest of the line) using shell\n# d, drop = remove commit\n```\n\n---\n\n# HOWTOs\n\n- How to pull commits from a remote repository without creating a merge commit ?\n```\n# git pull = git fetch + git merge\n# git pull --rebase = git fetch + git rebase\n$ git pull --rebase \u003cremote\u003e \u003cbranch\u003e\n```\n- How to set **rebase** as default ?\n```\n$ git config --global pull.rebase true\n```\n- How to solve conflict when rebasing ?\n```\n$ git pull\n# Snap! Conflict!\n$ vim \u003cfilename\u003e\n$ git add \u003cfilename\u003e\n$ git rebase --continue\n# Or if I want to abort\n$ git rebase --abort\n```\n\n---\n\n# HOWTOs\n\n- How to run some scripts before committing ?\n```\n$ mv .git/hooks/precommit.sample .git/hooks/precommit\n$ vim .git/hooks/precommit\n#!/bin/bash\nnpm run lint\nnpm run test\nnpm run build\n```\n\n- Git hooks are very handy to run scripts before or after some events :\n  - pre-commit\n  - pre-push\n  - pre-rebase\n  - prepare-commit-msg\n\n\u003c/script\u003e\n\n---\n\n# Git Flow\n\n- Master : protected production branch\n- Develop : protected staging branch\n- Feature branches :\n```\n# Create\n$ git checkout -b \u003cfeaturename\u003e develop\n# Merging\n$ git checkout develop\n$ git merge --no-ff \u003cfeaturename\u003e\n$ git branch -d \u003cfeaturename\u003e\n$ git push origin develop\n```\n- Release branches : naming convention e.g **release-**\n```\n$ git checkout -b release-\u003cversion\u003e develop\n# Bump version number\n$ git commit -a -m \"Bumped version number to \u003cversion\u003e\"\n$ git push origin release-\u003cversion\u003e\n# Merge in master\n$ git checkout master\n$ git merge --no-ff release-\u003cversion\u003e\n$ git tag -a 1.2\n# Merge in develop\n$ git checkout develop\n$ git merge --no-ff release-\u003cversion\u003e\n```\n\n---\n\n# Git Flow\n\n- Hotfix branches : naming convention e.g **hotfix-**\n```\n$ git checkout -b hotfix-\u003cnextversion\u003e master\n# First bump the version\n$ git commit -a -m \"Bumped version number to \u003cnextversion\u003e\"\n# Then fix the bug\n$ git commit -m \"Fixed severe production problem\"\n# Merge in master\n$ git checkout master\n$ git merge --no-ff hotfix-\u003cnextversion\u003e\n$ git tag -a \u003cnextversion\u003e\n# Merge in develop or in current release branch if release branch hasn't been merged yet\n$ git checkout develop\n$ git merge --no-ff \u003cnextversion\u003e\n```\n- See [Vincent Driessen's post](http://nvie.com/posts/a-successful-git-branching-model/) for more details\n\n---\n\n# Git Flow\n\n### Main branches\n![main-branches](./assets/main-branches.png)\n\n---\n\n# Git Flow\n\n### Feature branches\n![fb](./assets/fb.png)\n\n---\n\n# Git Flow\n\n### Merge without ff\n![merge-without-ff](./assets/merge-without-ff.png)\n\n---\n\n# Git Flow\n\n### Hotfixes branches\n![hotfix-branches](./assets/hotfix-branches.png)\n\n---\n\n# Git Flow\n\n![git-model](./assets/git-model.png)\n\n---\n\n# Advices\n\n- Use rebase !\n- Do not :\n```\n$ git add .\n$ git commit -a\n```\n- Before committing always :\n```\n$ git status\n$ git diff\n```\n- Use aliases\n```\nalias gst  ='git status'\nalias gd   ='git diff'\nalias gl   ='git pull'\nalias ga   ='git add'\nalias gc   = 'git commit -v'\nalias gc!  ='git commit -v --amend'\nalias gcn! ='git commit -v --no-edit --amend'\nalias gp   ='git push'\nalias gcb  ='git checkout -b'\nalias glog ='git log --oneline --decorate --graph'\n```\n\n---\n\n# Advices\n\n- Use [gitmoji](https://gitmoji.carloscuesta.me/)\n- Use git \u0026 github for your personnal projects to learn (like this presentation)\n\n---\n\n# The end.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatthieulemoine%2Fgit-training","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatthieulemoine%2Fgit-training","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatthieulemoine%2Fgit-training/lists"}