Skip to the content.

Git commands

git config

git config --global user.email "<email>"
git config --global user.name "<name>"

# change the default editor on Ubuntu
sudo update-alternatives --config editor

clear all local branches except main and current

git branch | egrep -v "(main|\*)" | xargs git branch -D

git stash

git diff

undo last local commit

revert a single commit

git relocate remote

updating from a cloned/forked repository

execute git in subfolder

helper function for working with multiple repositories in subfolders

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

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

working with git-flow branching

releasing a new version

conceptual description of the flow

detailed steps on GitLab

  1. via gitlab GUI create a MR from development into main
  2. when merged
  3. git checkout main - checkout main
  4. git checkout -b branch<new-version> - create a new branch
  5. npm version <patch | minor | major> - create the version
  6. git mwps-main - push branch and version tag, creating the MR.
  7. go to the MR on gitlab GUI and approve
  8. when done and merged
  9. via gitlab GUI create a MR from main back on development