-
Get all branches not merged to master
git branch --no-merged master
(see) -
Get all branches merged to master
git branch --merged
(see) -
Remove local branches that have gone remotes
git fetch --prune && git branch -lvv | cut -c3- | awk '/: gone]/ {print $1}' | xargs git branch -d
(see)git fetch -p && for branch in $(git branch -vv | grep ': gone]' | awk '{print $1}'); do git branch -D $branch; done
(see)
-
List of all revisions in branch
git rev-list master..aaa
(see)- For grandchildren
git rev-list ^master ^aaa bbb
([see](https://stackoverflow.com/questions/15589862/how-to-find-all-unmerged-
- For grandchildren
-
List of revision not merged to master
-
List of revisions to merge from master
git rev-list master --not aaa
(see). -
Get first accessor and application (see)
git config --global alias.oldest-ancestor '!zsh -c '\''diff --old-line-format='' --new-line-format='' <(git rev-list --first-parent "${1:-master}") <(git rev-list --first-parent "${2:-HEAD}") | head -1'\'' -'
- All changes in branch
git config --global alias.branchdiff '!sh -c "git diff `git oldest-ancestor`.."'
- Al commits in branch
git config --global alias.branchlog '!sh -c "git log `git oldest-ancestor`.."'
- All changes in branch
- Graph log (see)
log --all --decorate --oneline --graph
- How to get commits by users
git shortlog # or git shortlog -sne
- How to count changed lines before commit:
git diff --numstat #or git diff --shortstat
- Get commit hash prior another one
git rev-list --parents -n 1 42de6ad | awk -F ' ' '{print $2}'
- Get branches contain specific commit
git branch -a --contains 42de6ad
- Nearest parent branch
git log --pretty=format:'%D' HEAD^ | grep 'origin/' | head -n1 | sed 's@origin/@@' | sed 's@,.*@@'
- Current branch to variable
test=`git branch --show-current`
-
Pull master if curent branch is aaa
git pull origin master
-
Rebase all local commits on the top of master. To be exact move base commit and that apply all local commits on the top of the last one (see)
⚠️ do not use it if you have pushed commitsgit pull --rebase origin master
- Prepare merge request
(see)git config --global alias.tomerge '!currentBranch=\`git branch --show-current\`; tempBranch="${currentBranch}_tomerge"; git checkout -b "$tempBranch"; git checkout main; git rebase; git checkout $tempBranch; git rebase main; git reset $(git merge-base main $(git rev-parse --abbrev-ref HEAD)); git add -A'
find . -name "*" -exec git ls-files -s {} \;
https://stackoverflow.com/questions/38495989/how-to-get-git-parent-branch-name-from-current-branch
https://stackoverflow.com/questions/2706797/finding-what-branch-a-git-commit-came-from/40319739
https://stackoverflow.com/questions/43535132/given-a-commit-id-how-to-determine-if-current-branch-contains-the-commit
https://www.jetbrains.com/help/objc/apply-changes-from-one-branch-to-another.html