Skip to content

Instantly share code, notes, and snippets.

@vadimkantorov
Last active May 5, 2024 13:38
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 git@github.com:vadimkantorov/eventmapexample.git
cd eventmapexample
git remote add upstream git@github.com: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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment