Git is a software for tracking changes in any set of files. It works best for non-binary text files
Manage multiple repositories
Find all child repositories
Get-ChildItem -Path "." -Directory -Recurse |
foreach { $_.FullName } | foreach {
if (Test-Path -Path "$_\.git") {
Write-Output $_
}
}Pull all child repositories
Get-ChildItem -Path "." -Directory -Recurse |
foreach { $_.FullName } | foreach {
if (Test-Path -Path "$_\.git") {
Write-Host "$_`t" -f Cyan -NoNewline
git -C $_ pull
}
}Review and upload feature
rebase: review all feature commitsreword: rename commitsfixup: combine commits into a single one
push: upload current branch to remotepush: integrate current branch into remote’s main branchfetch: download remote branches
$currentBranch = (git branch --show-current).trim()
$mainBranch = (git symbolic-ref --short refs/remotes/origin/HEAD).replace("origin/","").trim()
git rebase --interactive origin/$mainBranch
if ($LASTEXITCODE -ne 0) {
git rebase --abort
} else {
git push origin $currentBranch":"$mainBranch
git pull origin $mainBranch":"$mainBranch
}In case main changed and changes have to be merged, do so and run
git rebase --continue
git push origin $currentBranch":"$mainBranch
git pull origin $mainBranch":"$mainBranchBranch handling
Squash multiple commits into one before pushing
git rebase --interactive origin/HEADPush my branch to remote’s main branch
$currentBranch = (git branch --show-current).trim()
$mainBranch = (git symbolic-ref --short refs/remotes/origin/HEAD).replace("origin/","").trim()
git rebase --interactive origin/$mainBranch
git push origin $currentBranch":"$mainBranch
git pull origin $mainBranch":"$mainBranchgit push origin current:main
git fetch origin main:main- abbreviate dirty:
git push origin $($(git branch --show-current).trim()+":"+(git symbolic-ref --short refs/remotes/origin/HEAD).replace("origin/",""))
Remove binaries from history
- Shrinks the repository size by excluding files or folders from the commit history.
- Rewrites all effected commits and their children to erase a folder/file from their changes.
- Avoid when collaborating, as it rewrites many commits.
Exclude a file
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch \"PATH/TO_ITEM\"' --prune-empty --tag-name-filter cat -- --allExclude a folder and its content
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch -r \"PATH/TO_ITEM\"' --prune-empty --tag-name-filter cat -- --allUseful commands
Amend all changes to previous commit
alias gitamend='git commit --amend --no-edit'Show git graph
git log --graph \
--abbrev-commit \
--pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'Alias
Alias internal command
git config --global alias.<shortcut> <command>- and call it using
git amend
Alias external command
git config --global alias.sourcetree '!/executable'Sources:
- 2022-12-14: Creating Git shortcuts
- 2023-06-19: git: Was ihr an der Uni noch nicht über die Versionsverwaltung gelernt habt. Ein praxisorientierter Workshop.
Related:
Tags: Computer Language
https://github.com/JohannesKaufmann/html-to-markdown https://github.com/dandavison/delta
Introduction - Mergiraf https://mergiraf.org/