Skip to content

Instantly share code, notes, and snippets.

@copdips
Last active May 18, 2025 10:07
Show Gist options
  • Save copdips/9147aacf03be04cda5cce03190ee9a34 to your computer and use it in GitHub Desktop.
Save copdips/9147aacf03be04cda5cce03190ee9a34 to your computer and use it in GitHub Desktop.
diff --git a/gitprompt.sh b/gitprompt.sh
index 978cae7..0f33e0e 100755
--- a/gitprompt.sh
+++ b/gitprompt.sh
@@ -649,7 +649,11 @@ function gp_add_virtualenv_to_prompt {
local ACCUMULATED_VENV_PROMPT=""
local VENV=""
if [[ -n "${VIRTUAL_ENV-}" && -z "${VIRTUAL_ENV_DISABLE_PROMPT+x}" ]]; then
- VENV=$(basename "${VIRTUAL_ENV}")
+ if [[ $VIRTUAL_ENV == "$(pwd)/.venv" ]]; then
+ VENV=$(basename "${VIRTUAL_ENV}")
+ else
+ VENV=$VIRTUAL_ENV
+ fi
+ PYTHON_VERSION=$(python --version | cut -d " " -f2)
+ VENV="$VENV $PYTHON_VERSION"
ACCUMULATED_VENV_PROMPT="${ACCUMULATED_VENV_PROMPT}${GIT_PROMPT_VIRTUALENV//_VIRTUALENV_/${VENV}}"
fi
if [[ -n "${NODE_VIRTUAL_ENV-}" && -z "${NODE_VIRTUAL_ENV_DISABLE_PROMPT+x}" ]]; then

Hey. # common git commands

git tag

sort git tag

git tag --sort -creatordate
git tag --sort -taggerdate --sort -committerdate
latestGitTag=$(git tag -l --sort=-version:refname | grep "^[0-9]" | head -n 1)

after pullrequest merge

# https://stackoverflow.com/a/14736749/5095636
# cut -c 4- means, take characters from fourth character
git st -s | cut -c4- | grep -E '.py' | while read f; do echo $f && isort --profile black $f && black $f ; done

# https://stackoverflow.com/a/5326684/5095636
#for changes relative to index
git diff --name-only

#for ... well staged chages :)
git diff --name-only --staged

# got both
git diff --name-only HEAD

format changed files only

git status -s | cut -c4- | grep .py | while read f ; do isort --profile black $f ; black $f;  done

install git on redhat

# https://www.tecmint.com/install-git-centos-fedora-redhat/
# https://git-scm.com/book/en/v2/Getting-Started-Installing-Git

yum update
yum groupinstall "Development Tools"
yum install gettext-devel openssl-devel perl-CPAN perl-devel zlib-devel
wget https://github.com/git/git/archive/v2.29.2.tar.gz -O git.tar.gz
tar -zxf git.tar.gz
cd git-2.10.1/
make configure
./configure --prefix=/usr/local
make all doc info
sudo make install install-doc install-info
git --version

mirror git repo with history

git clone --bare old_repo
cd old_repo
git push --mirror new_repo

find a string in the git log

git log -Spassowrd

find where a file was added

  1. all occurrences:

git ll -- file_name

  1. only added:

there're also A, M, D, etc. https://git-scm.com/docs/git-log#Documentation/git-log.txt---diff-filterACDMRTUXB82308203

git log --diff-filter=A -- file_name

force local maser to the same as origin/main

https://superuser.com/a/273199

git checkout -B main origin/main

git config

git config -l

git commit --amend --no-edit --author="Xiang ZHU <[email protected]>"

git config --global alias.amend=commit --amend -C HEAD
git config --global alias.st=status
git config --global alias.co=checkout
git config --global alias.last=log -1 HEAD
git config --global alias.ci=commit
git config --global alias.unstage=reset HEAD
git config --global alias.lga=log --graph --decorate --oneline --all
git config --global alias.ll=log --graph --all --pretty=format:'%C(auto)%h%Creset %an: %s - %Creset %C(auto)%d%Creset %C(bold black)(%cr)%Creset %C(bold black)(%ci)%Creset'
git config --global alias.sh=show
git config --global alias.df=diff
git config --global alias.br=branch
git config --global alias.cm=checkout main
git config --global alias.cd=checkout dev
git config --global alias.rum=pull --rebase upstream main
git config --global alias.rud=pull --rebase upstream dev
git config --global alias.rom=pull --rebase origin main
git config --global alias.rod=pull --rebase origin dev
git config --global color.ui=auto
git config --global core.editor=vim
git config --global core.filemode=false
git config --global core.autocrlf=input
git config --global core.quotepath=false
git config --global tag.sort=-v:refname
git config --global init.defaultbranch=main

git config --global diff.tool=defautl-difftool
git config --global difftool.default-difftoll.cmd=code --wait --diff $LOCAL $REMOTE
git config --global merge.tool=code
git config --global mergetool.code.cmd=code --wait --merge $REMOTE $LOCAL $BASE $MERGED
git config --global user.name=Xiang ZHU
git config --global [email protected]
git config --global user.signingkey=/home/xiang/.ssh/id_ed25519.pub
git config --global credential.helper=manager-core
git config --global init.templatedir=/home/xiang/.git-template
git config --global commit.gpgsign=true
git config --global gpg.ssh.allowedsignersfile=/home/xiang/.git-allowed-signers
git config --global gpg.format=ssh
git config --global core.repositoryformatversion=0
git config --global core.filemode=true
git config --global core.bare=false
git config --global core.logallrefupdates=trueAAA. 
git config --global [email protected]:copdips/react-course.git
git config --global remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
git config --global branch.main.remote=origin
git config --global branch.main.merge=refs/heads/main

Change user.email for Pernod Ricard repos

[email protected]
# git config user.email $pernod_email
cd ~/git
all_folders=$(ls -d $PWD/*)
echo $all_folders | tr ' ' '\n' | while read -r folder ; \
    do \
        echo ====== $folder ; cd $folder ; \
        url=$(git remote get-url origin 2>/dev/null) ; \
        if [[ -n $url ]] ; then \
            if [[ $url =~ "pernod" ]] ; then \
                echo ~~~is PR ; git config user.email $pernod_email ; \
            fi ; \
        fi ; \
        url= ; cd ~/git ; \
    done
# /home/xiang/.bash-git-prompt/gitprompt.sh
function get_git_message() {
# Check if the string contains a '/'
if [[ $GIT_BRANCH == */* ]]; then
# If it does, get the substring after the last '/'
MSG=${GIT_BRANCH##*/}
# Get the prefix by removing the message part from the original string
PREFIX=${GIT_BRANCH%$MSG}
else
# If it doesn't, the whole string is the message
PREFIX=""
MSG=$GIT_BRANCH
fi
# Replace "-" with " " in the message part
MSG=${MSG//-/ }
# Combine prefix and message into the new variable
if [[ -z $PREFIX ]]; then
export GIT_MESSAGE="$MSG"
else
export GIT_MESSAGE="${PREFIX}${MSG}"
fi
}
export GIT_BRANCH=$(replaceSymbols "${git_status_fields[0]}")
get_git_message
local GIT_REMOTE="$(replaceSymbols "${git_status_fields[1]}")"
git_clone_url="[email protected]:pernod-ricard/pr-github-actions-azure-pypi-publish.git"
modified_git_clone_url=${git_clone_url/github.com/github.com-pr}
cd ~/git
git clone $modified_git_clone_url
folder_name=$(basename "$modified_git_clone_url" .git)
cd "$folder_name"
git_useremail_pr
cp ../pr-github-actions-validate-pull-request-labels-for-version-bump/.gitignore .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment