Skip to content

Instantly share code, notes, and snippets.

@vadimkantorov
Last active December 25, 2024 19:22
Show Gist options
  • Save vadimkantorov/4b2e7e956bb76a3eed8978c1b213ecd0 to your computer and use it in GitHub Desktop.
Save vadimkantorov/4b2e7e956bb76a3eed8978c1b213ecd0 to your computer and use it in GitHub Desktop.
Various git tricks
# fork your own repo, example of my repo https://github.com/vadimkantorov/eventmap
git clone [email protected]:vadimkantorov/eventmapexample.git
cd eventmapexample
git remote add upstream [email protected]:vadimkantorov/eventmap.git
git pull upstream gh-pages
git checkout gh-pages
git push -u origin gh-pages
# update git to latest version on ubuntu
sudo add-apt-repository -y ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git -y
# clone only files in root and a directory, https://stackoverflow.com/questions/600079/how-do-i-clone-a-subdirectory-only-of-a-git-repository/52269934#52269934
git clone --depth 1 --filter=blob:none --sparse https://github.com/vadimkantorov/fastvideofeat
cd fastvideofeat
git sparse-checkout set paper
# delete branch both locally and on github, might need to first switch default branch from master to gh-pages in repo settings on github
git branch --delete master
git push origin --delete master
# GitHub: Rebase a pull request; fork into a private repo
# rebase a pull request
git remote add upstream https://github.com/pytorch/pytorch.git # do once
git fetch upstream master
# git rebase -i HEAD~2 # optional pick + squash
git rebase upstream/master
git push -f
# fork into a private repo from https://stackoverflow.com/a/30352360/445810
git clone --bare https://github.com/exampleuser/public-repo.git
cd public-repo.git
git push --mirror https://github.com/yourname/private-repo.git
cd ..
rm -rf public-repo.git
cd private-repo # pull changes from upstream
git remote add public https://github.com/exampleuser/public-repo.git
git pull public master # Creates a merge commit
git push origin master
# create an empty branch
git switch --orphan newbranch
git commit --allow-empty -m "Initial commit on orphan branch"
git push -u origin newbranch
# clone a given directory from a huge repo (e.g. https://github.com/torvalds/linux/tree/master/fs/isofs) https://stackoverflow.com/a/52269934/2988
git clone -n --depth=1 --filter=tree:0 https://github.com/torvalds/linux
cd linux
git sparse-checkout set --no-cone fs/isofs
git checkout
# search all git commits
git rev-list --all | xargs -L1 git grep CPATH
alias gitgrep='git rev-list --all | xargs -L1 git grep'
gitgrep CPATH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment