Skip to content

Latest commit

 

History

History
691 lines (601 loc) · 12.3 KB

git.md

File metadata and controls

691 lines (601 loc) · 12.3 KB

Git

Resources

Porcelain Commands

What are the porcelain commands?

Description

There are 145 commands in git in total, 82 porcelain commands and 63 plumbing commands.

  • 44 main commands add, commit, push, ...
  • 11 manipulators config, reflog, replace, ...
  • 17 interrogators blame, fsck, rerere, ...
  • 10 interactors send-email, p4, svn, ...

Resources


References

Plumbing Commands

What are the plumbing commands?

Description

There are 145 commands in git in total, 82 porcelain commands and 63 plumbing commands.

  • 19 manipulators apply, commit-tree, update-ref, ...
  • 21 interrogators cat-file, for-each-ref, ...
  • 5 syncing fetch-pack, send-pack, ...
  • 18 internal check-attr, sh-i18n, ...

Resources


References

Config

Conditionally use different git config file based on your project directory?

Description

A sample use case is to use different git config when you are in work and open source software directory.

[includeIf "gitdir:~/projects/work/"]
    path = ~/projects/work/.gitconfig

[includeIf "gitdir:~/projects/oss/"]
    path = ~/projects/oss/.gitconfig

Resources


References

Configure git to sign commits by ssh?

Description

git config --global gpg.format ssh
git config --global user.signingkey ~/.ssh/id_rsa.pub
git commit -S

You can see that your signature is appended to your commit files:

git cat-file -p HEAD

Resources


References

Alias

Use shell command as a git alias?

Description

git config --global alias.bb better-branch.sh

Resources


References

Branch

List available branches?

Description

Command branch will list branches each in a row.

git branch

Newer --column option will put branches on columns to avoid using a pager.

git branch --column

Resources


References

Enable column view of branches by default?

Description

git config --global column.ui auto
git config --global branch.sort -committerdate

Resources


References

Stash

What options can be used to stash all ignored and untracked files along unstaged files?

Description

git stash --all

It is suggested by the community to have this alias:

git config --global alias.staash 'stash --all'

Resources


References

Log

Log only a part of a file?

Description

git log -L 25,34:src/main.cpp

Resources


References

Search through the git history for a string that was removed?

Description

git log -S regex_match -p

Resources


References

Push

What is a safer mechanism to force push commits?

Description

Forcing push will remove all the changes that others have made since that last common change you have made. The option --force-with-lease will only pushes the rebased changes when there is no other changes pushed by other since your last common changes.

git push --force-with-lease

Resources


References

Push your sign along with pushing changes?

Description

This feature is not supported by GitHub or GitLab.

git push --signed

Resources


References

Clone

Partial Clone

How cloning can become faster?

Description

By partially cloning the repository and skipping the blobs:

git clone --filter=blob:none
git clone --filter=true:0

Resources


References

What is the downside of partial cloning?

Description

Graphs and blames will download the rest of required data on demand to generate results which will take time.

git clone --filter=blob:none
git blame lib/nlattr.c

Resources


References

Remote

List remote refs?

Description

git ls-remote

Resources


References

Fetch

Set fetch remotes to a project?

Description

git config remote.origin.fetch '+refs/pull/*:refs/remotes/origin/pull/*'
git fetch

Resources


References

Blame

Blame only a part of a file?

Description

git blame -L 25,34:src/main.cpp

Resources


References

Ignore white spaces in blame?

Description

git blame -w

Resources


References

Detect who moved or copied in the same commit in blame?

Description

git blame -w -C

Resources


References

Detect who created or changed the file in blame?

Description

git blame -w -C -C

Resources


References

Detect any commit that affects a line of code in blame?

Description

git blame -w -C -C -C -L 24,35:src/main.cpp

Resources


References

Reflog

What is a reflog?

Description

Reflog is a log of your references.

Whenever the HEAD is pointing at something, it has a log of that in reflog.

git reflog

Resources


References

Diff

Differentiate two commits by line?

Description

git diff

Resources


References

Differentiate two commits by word?

Description

git diff --word-diff

Resources


References

Reused Recorded Resolution

What is the advantage of using Reused Recorded Resolution?

Description

This feature records how you had a conflict and how you fixed it, so that it will solve your conflicts automatically next time you hit similar conflict.


Resources


References

Enable Reused Recorded Resolution feature?

Description

git config --global rerere.enabled true

Resources


References

Maitainance

What does maitainance start command do?

Description

It adds following lines to .git/config file:

[maintainance]
    auto = false
    strategy = incremental

Resources


References

What is the use case of maintainance command?

Description

By running maintainance, git starts a cron job running tasks reguarly.

A few of these tasks are:

  • gc: disabled
  • commit-graph: hourly
  • prefetch: hourly
  • loose-objects: daily
  • incremental-repack: daily
  • pack-refs: none

Resources


References

Commit Graph

What is the use case of commit graph command?

Description

Commit graph creates a graph of commits stored separately on disk and makes git commands very faster to run for large projects.

git commit-graph write

Resources


References

How often should we run commit graph command?

Description

This command should be done manually once, and then let git update the graph over next fetches.

git config --global fetch.writecommitgraph true

Resources


References

Filesystem Monitor

What mechanism can be used to increase the status command performance on big repositories?

Description

Launches a daemon that looks at the filesystem and watches for inode events and updates the cache in memory and tells git which files was changed every time git tries to stat the files.

git config core.untrackedcache true
git config core.fsmonitor true

First status command launches this mechanism, so it would make more time to finish, but subsequent calls will be fast.


Resources


References

Multipack Indexes

What is the impact of using multipack index mechanism?

Description


Resources


References


Reachability Bitmaps

Geometric Repacking

Sparse Checkout

Clone with no checkout?

Description

git sparse-checkout

Resources


References