- Crete branch, work, merge and delete
git checkout -b user/fix
echo fart >> new_file
git checkout master
git merge user/fix
git push -u origin master
git branch -d user/fix
git push origin -d user/fix
- Push on multiple remote at once
git remote add all git@github.com:xxxx/xxxx.git
# Re-register the remote as a push URL.
git remote set-url --add --push all git@github.com:xxxx/xxxx.git
# Add a push URL to a remote. This means that "git push" will also push to this git URL.
git remote set-url --add --push all git@bitbucket.org:xxxx/xxxx.git
-
Start to use newly created repo
git init ; git add * ; git commit -m "initial commit"; git remote add origin https://github.com/user/repo.git ; git push -u origin master
-
Force a git pull to overwrite local files
git fetch --all ; git reset --hard origin/master
-
Refusing to merge unrelated histories
git pull origin master --allow-unrelated-histories
-
Change account email address
git config user.email "admin@localhost";git config --global user.name "Infrastructure"
-
Repair merge
git merge --abort
git reset --merge
Remove broken files
git add files
git commit 'Repairing'
git push
-
Apply configuration system-wide
git config --add --system <OPTION>
-
Make a git pull on .git folder found in current folder and more (multi-threaded)
find . -name ".git" -type d | sed 's/\/.git//' | xargs -P10 -I{} git -C {} pull
-
Mirrorring a project with all code, branches, history
git clone --bare git@git.local.lol:group/project.git
-
Pushing a project with all code, branches, history
git push --mirror git@git.local.lol:group/project.git
-
Squashing old commits
git rebase --root -i
For each commit except the first, change pick to squash in the editor that pops up.
-
Cleaning
rm -Rf .git/refs/original rm -Rf .git/logs/ git gc --aggressive --prune=now git prune --expire now
-
Disable less for git commands
git config --global pager.branch false
-
Untrack files
git rm -r --cached .
git ls-files --ignored --exclude-standard -z | xargs -0 git rm --cached
- Git recursive (submodule configuration)
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[submodule]
active = .
[branch "master"]
remote = origin
merge = refs/heads/master
[submodule "xxxxx"]
url = https://github.com/xxxxx/xxxxx.git
[submodule "yyyyy"]
url = https://github.com/yyyyy/yyyyy.git
-
Pull recursive (submodules)
git clone https://github.com/xxxxx/yyyyy.git --recursive
-
Change file on every branch of a repository
#!/bin/bash
if [ $# != 1 ]; then
echo "usage: $0 <repository>"
exit;
fi
cd /tmp
folder_name=`echo "${1##*/}"|sed 's#.git##g'`
echo $folder_name
rm -rf $folder_name
git clone $1
cd $folder_name
ls
git fetch --all
my_callback () {
INDEX=${1}
BRANCH=${2}
echo "${INDEX} ${BRANCH}"
}
get_branches () {
git branch --all --format='%(refname:short)'
}
mapfile -t branches -C my_callback -c 1 < <( get_branches )
cat << EOF > /tmp/index.php
<?php
// Silence is golden.
EOF
for line in "${branches[@]}"
do
this_branch=`echo $line|awk -F '/' '{ print $2 }'`
if [[ $this_branch == 'HEAD' ]]
then
continue
else
echo $this_branch
git checkout $this_branch
git pull origin $this_branch
actual_filepath=`find . -regextype posix-egrep -regex "./wp-content/themes/index.php$"`
echo $actual_filepath
cp /tmp/index.php $actual_filepath
git add $actual_filepath
git commit -m 'Patched index.php (patched unwanted file)'
git push -u origin $this_branch
fi
done