Git: Difference between revisions

From Fundamental Ramen
Jump to navigation Jump to search
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Configuration ==
== Configuration ==


'''Current repo'''
=== Current repo ===


{| class="wikitable"
{| class="wikitable"
! _ || _
! Purpose || Command
|-
|-
| List user info for this repo ||
| List user info for this repo ||
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
git config --local --get-regexp "^user\."
git config --local --get-regexp "^u"
</syntaxhighlight>
</syntaxhighlight>
|-
|-
| Setup user for this repo. ||
| Setup user for this repo.<br/>(--comment must be placed before key) ||
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
git config --local user.name "name" --comment "User for work"
git config --local --comment "User for work" user.name "name"
git config --local user.email "name@mydomain.com" --comment "Email for work"
git config --local --comment "Email for work" user.email "name@mydomain.com"
</syntaxhighlight>
</syntaxhighlight>
|}
|}


'''All repos'''
=== All repos ===


{| class="wikitable"
{| class="wikitable"
! _ || _
! Purpose || Command
|-
| List user info and show it's scope.<br/>(--show-scope must be placed before --get-regexp) ||
<syntaxhighlight lang="bash">
git config --show-scope --get-regexp "^u"
</syntaxhighlight>
|-
|-
| Setup user and editor for all. ||
| Setup user and editor for all. ||

Latest revision as of 02:48, 16 July 2026

Configuration

Current repo

Purpose Command
List user info for this repo
git config --local --get-regexp "^u"
Setup user for this repo.
(--comment must be placed before key)
git config --local --comment "User for work" user.name "name"
git config --local --comment "Email for work" user.email "name@mydomain.com"

All repos

Purpose Command
List user info and show it's scope.
(--show-scope must be placed before --get-regexp)
git config --show-scope --get-regexp "^u"
Setup user and editor for all.
git config --global core.editor "vim"
git config --global user.name "name"
git config --global user.email "name@mydomain.com"

Maintainance

Purpose Command
Delete unused branches git branch -l feature/* | xargs git branch -d
git branch -l feature/* | xargs git branch -D
git branch -l feature/* bugfix/* hotfix/* | xargs git branch -D
Check why a file was ignored git check-ignore -v config.php
Clone a specific branch git clone -b staging project project_staging
Clear tags not in remote repository git fetch --prune --prune-tags

Undo

# Unstage a file
git reset --  src/sequelize-eparking/models/Fee.js

# Latest commit > stage
git reset HEAD^
git reset HEAD~1   # if symbol ^ escaped
git checkout upstream/develop composer.lock

Statistics

# stat for single commit
git diff 5741a4^..5741a4 --stat
git diff 5741a4^..5741a4 --shortstat

# Get commits count of someone.
git log --author='Me' --since='2019-01-01' --before='2019-12-31' | grep '^commit'
git log --author='Me' --since='2019-01-01' --before='2019-12-31' | grep '^commit' | wc -l
git diff 980b^ 980b | grep '^+[^+]' | wc -l
git diff 980b^ 980b | grep '^-[^-]' | wc -l
git diff 980b^ 980b | grep '^+++' | wc -l

Unknown

# See local and remote branches
git branch -v -a
master                                c313bf9 ...
remotes/origin/static-files-2         be32085 ...
remotes/origin/static-files-3         e9021d8 ...
...

# Checkout remote branch.
git checkout -b static-files-3 remotes/origin/static-files-3

https://docs.github.com/en/github/extending-github/git-automation-with-oauth-tokens