Git use cases
Git Branches
- list local and remote branches
git branch -av
- create and push a new branch
git checkout -b new-branch
git push -u origin new-branch
- delete a branch
git branch -d branch-name (delete it locally)
git push origin:branch-name (delete it on the remote repo)
- delete all gone branches
git pull --prune
git branch -vv | grep ': gone]'| grep -v "\*" | awk '{ print $1; }' | xargs -r git branch -D`
Local Changes
- stash local changes
git stash
git stash pop (retrieve the last entry)
...
git stash list
git stash apply stash@{2}
- commit local changes
git add -A
git commit -am “chore(ticket): description...”
...
git pull –rebase
git push
- change previous local commit
git commit --amend -m "feat: description..."
- retroactively sign all past commits
git rebase --exec "git commit --amend --no-edit -n -S" -i <branch you originally branched off>
- merge changes from main
git fetch
git merge origin/main
Merge conflict
If I have a merge conflict, instead of hitting that conflict through ~10 commits, I'd rather squash the branch and hit it once.
- reset merge when many conflicts
git reset HEAD --hard
git reset HEAD~. (undo last commit)
Git Tags
- see tags
git pull --prune --tags
git tag
- create local tag
caution
Ensure the tag does not exist in the remote repository
git tag -s v0.18.14 -m "Add possibility to cache node unit tests"
- delete local tag
git tag -d v0.18.14
- push tags
git push --tags