Skip to content

Latest commit

 

History

History
213 lines (156 loc) · 5.42 KB

git.md

File metadata and controls

213 lines (156 loc) · 5.42 KB

Git


Initialize a repo

git init
git add .
git commit -m 'Initial import.'
git remote add origin ${URL}
git push --set-upstream origin master

Show commit log with branches and tags

git log --graph --all --decorate

Create a patch

git diff --patch-with-raw > out.patch
git diff HEAD~1 --relative

Create a symbolic branch link

git symbolic-ref refs/heads/master refs/heads/main

Fetch changes from origin/master without checking out master

Git alias

git checkout --detach --quiet HEAD && git fetch origin master:master && git checkout --quiet -

Clean-up local branches

git branch --merged
git branch -d merged-branch-name
git branch --no-merged
git branch -D un-merged-branch-name

Prune tracking branches

git gc --prune=now
git prune
git remote prune origin

git branch -r
git remote prune origin

# Or just fetch with -p
git fetch -p

List merged branches on origin

for branch in `git branch -r --merged | grep -v HEAD`; do \
	echo -e `git show --format="%ci %cr %an" $branch | head -n 1` \\t$branch; \
done | sort -r

See commit history for the last two commits, including the diff

git log -p -2

Squash all but first commit

git rebase -i $(git rev-list --max-parents=0 HEAD)
# Change all but the first "pick" to "squash"
git push --force

# Alternatively:
git rebase -i --root

Pull a --force pushed branch

git fetch
git reset origin/$(git branch --show-current) --hard

Change origin URL

git remote set-url origin git://$URL

Project-specific configuration

git config user.name "andornaut" \
    && git config user.user "andornaut" \
    && git config user.email "[email protected]"

Convert a mercurial repo to git

hg-fast-export

mkdir repo-git
cd repo-git
git init
hg-fast-export.sh -r <repo> -B <branches_map> -A <users_map>

Ignore/unignore changes to a file

# Ignore
git update-index --assume-unchanged ${filepath}

# Unignore
git update-index --no-assume-unchanged ${filepath}

Delete tag

git tag -d v0.0.1
git push origin :refs/tags/v0.0.1

Undo commits

# Revert a merge commit
git revert -m 1 ${MERGE_COMMIT_SHA}

Get default branch name

[alias]
    dbr = !bash -c 'set -o pipefail && git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null|cut -d / -f 4-||git remote show origin 2>/dev/null|awk \"/HEAD branch/ {print \\$NF}\"||echo main'

Set default branch

Stackoverflow - Allow git to set your origin/HEAD, determining what branch to use automatically

git remote set-head origin --auto

Github

Collapsable section markdown

<details><summary>Click here to expand</summary>

This section is hidden until the above is clicked.
</details>

Search

# What
archived:false
is:closed
is:pr,issue

# Who
org:wmgtech
author:andornaut
involves:andornaut
reviewed-by:andornaut
# PRs where andornaut is a reviewer and not author
reviewed-by:andornaut -author:andornaut

# Date/time
created:>=2024-12-31 
merged:2024-01-01..2024-12-31

Example searches:

Tips