The almighty Oh Shit, Git!?! has all the answer when you have, once again, fucked things up with git.
Learn from this game Oh My Git!.
Retrieve older versions of a file
git reflog <file> git checkout <commit-id> -- <file>
Fetch & Merge Upstream into Fork
- Syncing a fork - GitHub Docs
- bassistance.de » Git fu: Updating your GitHub fork
- Force your forked repo to be the same as upstream. · GitHub
- How to Clone into a Non-Empty Git Directory
git remote add upstream firstname.lastname@example.org:original-repo.git git fetch upstream git merge upstream/main git push
# Letzten Commit im aktuellen Branch löschen git reset --hard HEAD~1 # Spezifischen Commit löschen git reset --hard <sha1-commit-id> # Danach muss 1x so gepusht werden: git push origin HEAD --force
git revert <commit>
You should really only use
resetif the commit being reset only exists locally. This command changes the commit history and it might overwrite history that remote team members depend on.
revertinstead creates a new commit that undoes the changes, so if the commit to revert has already been pushed to a shared repository, it is best to use
revertas it doesn’t overwrite commit history.
With ssh superpowers
Move current uncommitted changes to new branch
git switch -c <branch>
error: src refspec main does not match any→
error: failed to push some refs to github
What if I want a local-only .gitignore?
Patterns which are specific to a particular repository but which do not need to be shared with other related repositories (e.g., auxiliary files that live inside the repository but are specific to one user’s workflow) should go into the
$GIT_DIR/info/excludefile. – gitignore#_description
HTTPS to SSH URLs
git remote set-url origin email@example.com:MAINTAINER/REPO.git # Replace origin with whatever