git config --global user.email "<email>"
git config --global user.name "<name>"
# change the default editor on Ubuntu
sudo update-alternatives --config editor
git branch | egrep -v "(main|\*)" | xargs git branch -D
- git stash list:
git stash list
- git stash show diff:
git stash show -p stash@{0}
- git stash drop:
git stash drop stash@{0}
- git diff unpushed changes:
git diff origin/<branch>
- soft - keeping local changes:
git reset --soft HEAD~1
- hard - discard local changes:
git reset --hard HEAD~1
git revert <sha>
git remote set-url origin <remote url>
git -C <folder> <command>
Insert in ~/.bash_aliases
# command for executing a git command in all git sub folders
# usage:
# git-sub status show git status
# git-sub fetch origin fetch origin information
# git-sub branch show branches (local)
#
# use -i as first argument for interactive mode
git-sub () {
interactive=''
if [ "$1" == "-i" ]
then
shift
interactive='-p'
fi
if [ $# -eq 0 ]
then
echo "usage: git-sub <git commands>"
echo " use '-i' as first arugment for interactive mode"
return 1
fi
find . -maxdepth 3 -name .git -type d | rev | cut -c 6- | rev | xargs $interactive -I {} sh -c "echo '\n\033[1;32m{}\033[0m' && git -C {} $@"
}
using GitLab push options to create a MR from command line
Note this is limited by the fact that you can only push
(and thereby only push client side options) when git push
has work to do. If you have nothing to push you will get an 'Everything up-to-date' info message from git push
.
create a git alias
- which is named
mwps-main
(merge when pipeline succeeds) - that creates a merge request with target
main
that automatically merges - set the upstream branch to the same name as the current local branch (indicated by
origin HEAD
) - also pushes any tags - e.g. created by
npm version
git config --global alias.mwps-main "push -o merge_request.create -o merge_request.target=main -o merge_request.merge_when_pipeline_succeeds --set-upstream origin HEAD --follow-tags"
use the alias
git mwps-main
- will push and create a MR on gitlab from the current branch
conceptual description of the flow
- merge
development
intomain
- create a new version and tag on
main
- merge
main
back intodevelopment
detailed steps on GitLab
- via gitlab GUI create a MR from development into main
- when merged
git checkout main
- checkout maingit checkout -b branch<new-version>
- create a new branchnpm version <patch | minor | major>
- create the versiongit mwps-main
- push branch and version tag, creating the MR.- go to the MR on gitlab GUI and approve
- when done and merged
- via gitlab GUI create a MR from main back on development