git.md 3.3 KB

Git

Useful git commands and workflow.

Workflow

Branching model

For a good workflow with branches, see this article.

Commit

Use emojis to categorize the commit.

  • :tada: :tada: | When you added a cool new feature.
  • :wrench: :wrench: | When you tweaked some parameters.
  • :recycle: :recycle: | When you refactored a part of the code.
  • :sparkles: :sparkles: | When you applied a linter.
  • :globe_with_meridians: :globe_with_meridians: | When you worked on translations.
  • :art: :art: | When you improved / added grahics assets like themes.
  • :lipstick: :lipstick: | When you worked on the UI.
  • :rocket: :rocket: | When you improved performance.
  • :memo: :memo: | When you wrote documentation.
  • :beetle: :beetle: | When you fixed a bug.
  • :revolving_hearts: :revolving_hearts: | When a new sponsor / contributor is added or credits are updated.
  • :heavy_check_mark: :heavy_check_mark: | When you worked on checks or adjusted the code to be compliant with them.
  • :twisted_rightwards_arrows: :twisted_rightwards_arrows: | When you merged a branch.
  • :fire: :fire: | When you removed something.
  • :truck: :truck: | When you moved / renamed something.

Thanks for Desktop-Cube author for the idea.

Configuration

git config --global user.email "contact@jovian-hersemeule.eu"

git config --global user.name "DricomDragon"

git config --global core.editor "vim"

git config --global push.followTags true

git config --global diff.tool vimdiff

You can replace --global by --local to configure a specific project.

Useful commands

Staging

git status -s

git diff for difference against unstaged files

git diff --staged or git diff --cached for difference against staged files

git rm --cached <file> remove a file from git but keep this file on drive

Stashing

git stash -u -m 'Experiment optimized code

-u is used to stash untracked files

Diff tool

git difftool use a tool like vimdiff

git difftool --tool-help see availble git diff tools

See config for setting his own git tool for diff.

Powerful history

git commit -v see diff while committing

git log -p see diff for every commit

git log --graph see branches history

git log --stat see numbers of modifs on each file for every commit

Remote

git remote show <remote_name> show useful information about remote

git push --delete <remote_name> <branch_name> delete a remote branch

Review every files edited on your branch

git diff dev --numstat | cut -f 3 | sed -e 's/{.* => \(.*\)}/\1/g' show every modified files since dev

grep -e 'TODO' (git diff dev --numstat | cut -f 3 | sed -e 's/{.* => \(.*\)}/\1/g') show every TODO in modified files

vim (git diff dev --numstat | cut -f 3 | sed -e 's/{.* => \(.*\)}/\1/g') open every file in your text editor

GitAhead

Open-source cross-platform Git GUI

https://gitahead.github.io/gitahead.com/

Global config

Tools > Config

You can disable fetch every 10 min for instance.

Global gitignore in Windows

Use same config file as GitBash.

Use in gitbash : git config --global core.excludesfile '~/.gitignore'

Do not forget to copy your .gitignore at the right place.