Git

GIT #

SSH throws error: “no matching host key type found. Their offer: ssh-rsa” #

Add the following in the ~/.ssh/config relevant host section

HostKeyAlgorithms +ssh-rsa
PubkeyAcceptedKeyTypes +ssh-rsa

Delete local branch #

git branch -d <local-branch>

Delete remote branch #

git push origin --delete <remote-branch-name>

Show remote configuration #

git remote -v

Commit Concepts #

Commits are snapshots of file structure, not a list of changed files. Diffs are only generated on the client by comparing a commit to it’s parent(s) commits

A merge commit is a commit that has more than 1 parents. A merge operation is performed by getting the diffs of the branches since their common ancestor, and then applying these changes to the target.

TortoiseGit: Reset git submodules to the commit pointing by the parent repo #

TortoiseGit > Submodule update > check ‘init’’ and ‘Force’

TortoiseGit: Fix “No supported authentication methods available (server sent: publickey)” error #

Use PuTTy to set a default key for all SSH connections:

  • Start PuTTY, go to Connection->SSH->Auth and select your private key.
  • Go to Session, select Default Settings and hit Save.

Mirror repo to another remote #

Initial mirror

git clone --mirror SOURCE_REPO_URL
cd SRC_GIT.git
git push --mirror TARGET_REPO_URL

Incremental push TO SYNC NEW COMMITS

git remote update
git push --mirror TARGET_REPO_URL

To view current remotes #

git remote -v

To add a new origin #

git remote add origin NEW_REPO_URL

To change origin #

git remote set-url origin NEW_REPO_URL

To remove an already committed file #

  • Add the file/folder you want to ignore in .gitignore
  • Execute the following command: git rm --cached path/to/file. Git will list the files it has deleted. The --cached flag should be used if you want to keep the local copy but remove it from the repository.
  • Verify that these files are being deleted from version control using git status.
  • Commit and push the changes to the repository.

View the submodule commit hash that the parent repo is pointing to #

On the submodule parent directory do :

git ls-tree HEAD

The submodule commit sha will be shown before the submodule directory name

Detect secrets before committing #

https://github.com/awslabs/git-secrets

To install on windows

  • Clone the repo
  • Open powershell
  • Run ./install.ps1
  • git secrets –register-aws –global

To scan a repo with history

git secrets --scan-history

To exclude warnings about AWS account id

git secrets --add -a '("|'')?(AWS|aws|Aws)?_?(ACCOUNT|account|Account)_?(ID|id|Id)?("|'')?\s*(:|=>|=)\s*("|'')?[0-9]{4}\-?[0-9]{4}\-?[0-9]{4}("|'')?'

Git commit message structure #

https://www.conventionalcommits.org/en/v1.0.0/#summary

<type>[optional scope]: <description>
[optional body]

[optional footer(s)]

Detached heads #

Detached heads are commits that do not have any branch or tag points to them. They can be lost, because they are not pushed to remotes since pushing to remote requires specifying a tag or branch.

Resources #