Git is a popular Version Control Software (VCS) optimized for text files e.g. Software source code.
Git isn't good at handling binary files and it is considered best practice to avoid including big binary blobs like compiled binaries, firmware images, movies, and so on.
- TOOD: git webguide(s).
- TODO: Mandatory config - username + email.
- TODO: Identity config.
- TODO: Keeping a global gitignore file in your homedir.
- TODO: Rename default branch back to 'master'.
- TODO: Moving config between machines.
- TODO: Scripting git config CLI.
- TODO: templating git config file format.
System: Systemwide for all users.
Global: For the system user.
Local: For the repo.
Example of file locations for different scopes
# Via: $ git --no-pager config --show-scope --show-origin --list
## SCOPE ORIGIN KEY=VALUE
system file:C:/Program Files/Git/etc/gitconfig core.autocrlf=true
global file:C:/Users/User/.gitconfig core.autocrlf=false
local file:.git/config core.bare=false
Disabling CRLF conversion (\n <-> \r\n)
git config --global core.autocrlf=falseConfiguration specific to one git repository.
Create a file named .gitattributes in the repository root dir.
- https://www.git-scm.com/docs/gitattributes
- https://docs.github.com/en/get-started/getting-started-with-git/configuring-git-to-handle-line-endings#per-repository-settings
Setting config values to repo-local scope:
## $ git config --local KEY=VALUE
git config --local core.autocrlf=falseListing only repo-local settings:
git config --local --listShow active config values:
## KEY=VALUE
git --no-pager config --listShow active config including scope:
## SCOPE ORIGIN KEY=VALUE
git --no-pager config --show-scope --listShow active config including scope and origin:
## SCOPE ORIGIN KEY=VALUE
git --no-pager config --show-scope --show-origin --list- TODO: Guide on branching and at least one example viable development workflow using branching.
DESCRIPTION
TODOListing remotes on git a repository:
git remote --verboseTo add a remote:
git remote add home-server "ssh://git@10.1.1.69:/~/my-project.git"To push to a remote:
git push home-serverTo remove a remote:
git remote remove home-serverTo init and push an exisitng repository to a home git server:
Create bare repo to push to: (On server)
## As: dev@home-server:~$
## Init bare repo on git server:
## Alternative?: # sudo -u "git" git init --bare "/home/git/my-project.git"
dev@home-server:~$ sudo -u git /usr/bin/bash
git@home-server:~$ git init --bare development-pointers.public.git
## Ensure client's pubkey is present:
dev@home-server:~$ sudo -u "git" nano "/home/git/.ssh/authorized_keys"Add reference to remote and push repo data: (On client / workstation)
## As dev@workstation:~/repos/my-project$
## Add reference to remote to local git repository:
git remote add home-server "ssh://git@10.1.1.69:/~/my-project.git"
## Push repo to remote:
git push home-servere.g. for lan server selfhosting
Init bare repo:
git init --bare "/home/git/my-project.git"Example: sudo into git account to init bare repo on git server:
$ sudo -u "git" git init --bare "/home/git/my-project.git"Add remote to reference server:
~/repos/my-project$ git remote add origin "ssh://git@10.1.1.69:/~/my-project.git"- TODO: ssh auth
- TODO: Env vars.
- TODO: GNUPG integration.
- TODO: Signing commits.
- TODO: 2FA.
Create a new empty repository in the current dir:
git init .## git clone SOURCE_REPO [DEST]
git clone https://github.com/example/example.gitPushing to default upstream:
git pushPulling from default upstream (usually brings working files to latest upstream commit):
gut pullRetrieving new changes from upstream without changing current working files:
git fetchStage file(s) for commit. (Record the state of the staged files in preparation for committing them.)
## $ git stage [FILE...]
git stage ./some-fileCommit staged changes: (Persist the state of the staged files to the repo.)
git commit -m "Some message from the commandline, as an example."Sometimes git clone errors out from network troubles; how to fix that?
To make git work even if network connection is unreliable.
- "How to retry when git clone fail?" (stackoverflow)
- "The cloning process can be interrupted due to unstable network condition and cannot be resumed. #7440" (github repo "desktop/desktop")
GIT_HTTP_LOW_SPEED_LIMITandGIT_HTTP_LOW_SPEED_TIME"10.8 Git Internals - Environment Variables" (git documentation - Book)- "git-config - Get and set repository or global options"(git documentation - Reference)
Set git config file values to configure git's HTTP mode to tolerate up to a minute of being under 1KiB/sec: (untested)
## https://git-scm.com/docs/git-config/2.22.0#Documentation/git-config.txt-httplowSpeedLimithttplowSpeedTime
## Control when git gives up when using curl: (Overriden by env vars)
git config --global http.lowSpeedTime=60 # Seconds.
git config --global http.lowSpeedLimit=1024 # Bytes per second.Use env vars to tell git's HTTP mode to tolerate up to a minute of being under 1KiB/sec: (untested)
## See: https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables
export GIT_CURL_VERBOSE="1" # Similar to 'curl -v'
export GIT_HTTP_LOW_SPEED_LIMIT="1024" # Bytes per second.
export GIT_HTTP_LOW_SPEED_TIME="60" # Seconds.
## After env vars are set git should tolerate low transfer rates.
git clone https://REPO_URLHow to use one command to push to multiple remotes. e.g. simultaneously push to homeserver, github, gitgud, etc.
- TODO: Figure this out.
gitlab suggested push:
git remote rename origin old-origin
git remote add origin git@ssh.gitgud.io:Ctrl-S/development-pointers.git
git push --set-upstream origin --all
git push --set-upstream origin --tagsgit remote add github git@github.com:woodenphone/development-pointers.git
First connect directly to host via putty to accept the host key, then retry git operation.
Message given:
The server's host key is not cached. You have no guarantee
that the server is the computer you think it is.
The server's ssh-ed25519 key fingerprint is:
ssh-ed25519 255 SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU
If you trust this host, enter "y" to add the key to
PuTTY's cache and carry on connecting.
If you want to carry on connecting just once, without
adding the key to the cache, enter "n".
If you do not trust this host, press Return to abandon the
connection.
Store key in cache? (y/n, Return cancels connection, i for more info)
Push to all remotes with one command. Use a special remote that points at all remote dests, both public and privately hosted ones.
git remote add Methods to do the task I found.
Using a special remote with multiple URLs:
git remote add all git://original/repo.git
git remote -v ## List remotes.
git config -l | grep '^remote\.all' ## Show config for 'remote.all'
git remote set-url --add --push all git://another/repo.git
git remote -v ## List remotes.
git config -l | grep '^remote\.all' ## Show config for 'remote.all'
git remote set-url --add --push all git://original/repo.gitUseing a git alias:
git config alias.pushall '!git push origin devel && git push github devel'This method I have tested.
Excerpt of the contents of .git/config
[remote]
## Override default to push to all remotes
## i.e. Make '$ git push' behave like '$ git push pushall'
## remote.pushDefault "The remote to push to by default" - git-config(1) manpage
pushDefault = pushall
[remote "pushall"]
## Convenience pseudoremote to push to all remotes at once
## remote.<name>.url "first is used for fetching, and all are used for pushing" - git-config(1) manpage
# url = git://original/repo.git
## remote.<name>.pushurl - git-config(1) manpage
pushurl = git@github.com:woodenphone/tmux-dump-session.git
pushurl = git@ssh.gitgud.io:Ctrl-S/tmux-dump-session.git
pushurl = ssh://git@PERSONAL_GIT_SERVER_IP_REDACTED:/~/tmux-dump-session.git- Configuration File git-config(1) manpage
remote.<name>.urlgit-config(1) manpageremote.<name>.pushurlgit-config(1) manpageremote.pushDefaultgit-config(1) manpage
To push to all remotes (explicitly referencing 'pushall' remote):
git push pushall -v(-v increases verbosity)
To push to all remotes (implicitly due to remote.pushDefault):
git push -vLinks related to pushing to multiple remotes in one command.
- https://www.kernel.org/pub/software/scm/git/docs/git-config.html
- https://git-scm.com/docs/git-config
- "Configuration File" git-config(1) manpage
remote.<name>.urlgit-config(1) manpageremote.<name>.pushurlgit-config(1) manpageremote.pushDefaultgit-config(1) manpage- https://stackoverflow.com/questions/14290113/git-pushing-code-to-two-remotes#14290145
Show the configuration specific to this repo:
git config --list --local ## Show configuration for this repo (local scope).Show a list of remotes:
git remote --verbose ## Show remotes for this repo.How to figure out where config values are coming from.
$ git config --list --show-scope --show-origin ## Show currently active configuration, explicitly listing scope and where the value came from.
>local file:.git/config core.repositoryformatversion=0- Information on git scopes: https://git-scm.com/docs/git-config#SCOPES
Creating git repos from existing codebase history:
Relevant files included in this repo.
*"git(1)" - "git - the stupid content tracker" *"" *""
*"" *"CRLF vs. LF: Normalizing Line Endings in Git"
https://docs.github.com/en/get-started/getting-started-with-git/configuring-git-to-handle-line-endings https://docs.github.com/en/get-started/getting-started-with-git/managing-remote-repositories
- https://www.kernel.org/pub/software/scm/git/docs/git-config.html
- https://git-scm.com/docs/git-config
- "Configuration File" git-config(1) manpage
remote.<name>.urlgit-config(1) manpageremote.<name>.pushurlgit-config(1) manpageremote.pushDefaultgit-config(1) manpage- https://stackoverflow.com/questions/14290113/git-pushing-code-to-two-remotes#14290145