Skip to content

Latest commit

 

History

History
78 lines (60 loc) · 3 KB

git.md

File metadata and controls

78 lines (60 loc) · 3 KB
date published categories tags
2023-09-07
true
notes
development
software

Git

The version control system (VCS), if you somehow aren't familiar.

First created by Linus Torvalds for the [[Linux]] Kernel project, now the most popular VCS in the world.

Useful Actions/Commands

Delete Last Commit

reset HEAD^ will delete the last commit, with no confirmation. Be careful.

Show Log with File Changes

log --stat will display the log with file changes for each commit.

Configure Git for Both Work & Personal Profiles

Git version 2.36 introduced a new includeIf conditional, hasconfig:remote.*.url:, which allows you to conditionally load a config file based on if a specific URL exists within the remote config for the repo you are currently working with. With this new feature, you can easily configure Git for home/personal usage, or any given org.

If you're using GitHub, that would look like:

# Common Settings:
[user]
    name = Firstname Lastname
# Personal Settings:
[includeIf "hasconfig:remote.*.url:[email protected]:firstnamelastname/**"]
    path = "~/.gitconfig-personal"
# Work Settings:
[includeIf "hasconfig:remote.*.url:[email protected]:acmeinc/**"]
    path = "~/.gitconfig-work"

Using Only 2 Files

Or if you don't want 3 files, you can have one just override the others by piling everything into ~/.gitconfig and then just using ~/.gitconfig-work to overwrite things like your email address:

~/.gitconfig

# Personal Settings:
[user]
    name = Firstname Lastname
    email = [email protected]
# Work Settings that will add to or overwrite personal settings:
[includeIf "hasconfig:remote.*.url:gitlab.acmeinc.com/**"]
    path = "~/.gitconfig-work"

~/.gitconfig-work

[user]
    # This will overwrite your personal email address with your work one:
    email = [email protected]

Alternatives to hasremote

Also consider includeIf "gitdir:" if this won't work for you, which will include a config fle based on the name/path of the git repository.

Git LFS

A plugin for Git that stores designated large files externally, so that the repository itself doesn't get too large or slow to work with.

With LFS, you need to explicitly "track" files using git lfs track <pattern>, otherwise they will be treated like all other files. This <pattern> is often an extension like *.pdf.

This command amends your repository's .gitattributes file and associates large files with Git LFS. 1

When you push a file that matches one of these patterns, they will now be uploaded to the server to handle in an alternative way, leaving only a reference to the file in the repository itself, and thus keeping the repository size small.