You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2.5 KiB



Clone with submodule recurse

add --recurse-submodules to clone command

Add in staging only a part of modification done in a file

git add -p

this will ask if you want to add each modification with this option:

  • y - Yes, add this hunk
  • n - No, don’t add this hunk
  • d - No, don’t add this hunk and all other remaining hunks. Useful if you’ve already added what you want to, and want to skip over the rest
  • s - Split the hunk into smaller hunks. This only works if there’s unchanged lines between the changes in the displayed hunk, so this wouldn’t have any effect in the example above
  • e - Manually edit the hunk. This is probably the most powerful option. As promised, it will open the hunk in a text editor and you can edit it to your hearts content

delete a file only from git repository

git rm -rf --cached

delete a file from complete history

be carefull can't push repo last time use need to be in a repo with no modification

git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch $file" HEAD
rm -rf .git/refs/original/ && git reflog expire --all &&  git gc --aggressive --prune

create a repo from other repo subfoler

  • clone the first repo
  • go in this directory
  • launch
git filter-branch --prune-empty --subdirectory-filter "subdirectory/path" master
  • push in your new git repo

changing email adress

$ git filter-branch --commit-filter '
        if [ "$GIT_AUTHOR_EMAIL" = "schacon@localhost" ];
                GIT_AUTHOR_NAME="Scott Chacon";
                git commit-tree "$@";
                git commit-tree "$@";
        fi' HEAD

example de déclencheur git dans un dépot git

# get branch name
if ! [ -t 0 ]; then
  read -a ref
IFS='/' read -ra REF <<< "${ref[2]}"

if [ "master" == "$branch" ]; then
mkdir -p $TMP_GIT_CLONE
echo "download repo"
git clone --recursive $GIT_REPO $TMP_GIT_CLONE
export PATH="$HOME/.local/bin:$PATH"
make install -e BUILDDIR=$PUBLIC_WWW
echo "Cleaning up"

use git ssh over proxy socks

export GIT_SSH_COMMAND='ssh -o ProxyCommand="nc -X 5 -x %h %p"'

use git http over proxy socks

git config http.proxy 'socks5://