Skip to content

Latest commit

 

History

History
344 lines (204 loc) · 9.68 KB

File metadata and controls

344 lines (204 loc) · 9.68 KB

Tips.Git.md

Useful Tools

References

Useful References

Git Communities

Tips Lists by Others

Git Tutorial Resources

Git File Tips

  • Put a .gitignore containing a single asterisk in your scratch directories

Git Statistics, Visualization

Commit Message Standards

Commit Message Format

  • <type>(<scope>): <subject>
  • <body>
  • <footer>

Example values:

Type Definition
feat (new feature for the user, not a new feature for build script)
fix (bug fix for the user, not a fix to a build script)
docs (changes to the documentation)
style (formatting, missing semi colons, etc; no production code change)
refactor (refactoring production code, eg. renaming a variable)
test (adding missing tests, refactoring tests; no production code change)
chore (updating grunt tasks etc; no production code change)

Example Subject Line Standard Terminology

First Word Meaning
Add Create a capability e.g. feature, test, dependency.
Cut Remove a capability e.g. feature, test, dependency.
Fix Fix an issue e.g. bug, typo, accident, misstatement.
Bump Increase the version of something e.g. dependency.
Make Change the build process, or tooling, or infra.
Start Begin doing something; e.g. create a feature flag.
Stop End doing something; e.g. remove a feature flag.
Refactor A code change that MUST be just a refactoring.
Reformat Refactor of formatting, e.g. omit whitespace.
Optimize Refactor of performance, e.g. speed up code.
Document Refactor of documentation, e.g. help files.

Git News

Downloads

Git Code Review Tools

Useful Git Articles

Useful Supplemental Tools

Interesting Github Projects

Useful Git Commands

  • Count number of commit (in a repository)
    • git log --oneline | wc -l

Git Command Examples

  • Configure Git on Windows for long path

    • git config core.longpaths true
  • Determine size of a git repository:

    • $ git count-objects -vH
    • Example output: *count: 1594
      • size: 1.05 MiB
      • in-pack: 0
      • packs: 0
      • size-pack: 0 bytes
      • prune-packable: 0
      • garbage: 0
      • size-garbage: 0 bytes
  • Branch Management:

    • Show list of branches
      • git branch
    • Show current branch:
      • git branch --show-current
    • Switch branch:
      • git checkout master
      • or
      • git checkout main
    • Rename your local master branch to main:
      • git branch -m master main
    • Push the new local main branch to the remote repository (if it doesn't already exist from the GitHub setting change) and set it as the upstream:
      • git push -u origin main
    • Ensure your local repository's HEAD is pointing to the new default remote branch:
      • git fetch origin
      • git remote set-head origin -a
      • Or, specifically set the upstream for your local main branch:
        • git branch -u origin/main main
    • (Optional) Delete the Old master Branch:
      • git push origin --delete master
    • Any other developers working on the repository will need to update their local clones by running these commands in their local repositories:
      • git fetch --prune origin
      • git checkout main (or git switch main for newer Git versions)
      • git branch -u origin/main main
  • Determine URL that a local Git repository was originally cloned from

    • git config --get remote.origin.url
    • git remote show origin
    • git remote -v
    • git ls-remote --get-url
  • Tell Git to remember your credentials (on Windows)

  • When a checkout fails...

    • You can inspect what was checked out with git status...and retry the checkout with
      • git checkout -f HEAD
  • To fetch a file from another branch to the current one:

    • git checkout branch_name -- filename
  • To unstage a git add <file>

    • git reset <file>
  • To Amend a Commit Message

    • Git commit --amend
  • TO backdate commits

    • git commit --date <date>
  • To Check out the origin/master branch and then reset master branch there

    • git checkout -B master origin/master
  • “top ten list” of most commited files

    • git log --pretty=format: --name-only | sort | uniq -c | sort -rg | head -10
  • Graphically show commits across different branches

    • git log --graph --oneline --decorate --date=relative --all
  • overwrite only one file:

    • git fetch
    • git checkout origin/main <filepath>
  • overwrite all changed files:

    • git fetch
    • git reset --hard origin/main