Skip to content

Instantly share code, notes, and snippets.

@MizterB
Last active March 11, 2022 13:06
Show Gist options
  • Save MizterB/3f61c38bcbaae27522c6d07a926c64c5 to your computer and use it in GitHub Desktop.
Save MizterB/3f61c38bcbaae27522c6d07a926c64c5 to your computer and use it in GitHub Desktop.
Git Cheat Sheet

THIS WORKED -Force your forked repo to be the same as upstream.

https://gist.github.com/glennblock/1974465 Leading to: 684 git checkout dev 704 git fetch upstream 705 git reset --hard upstream/dev 706 git push origin dev --force

https://github.com/emesene/emesene/wiki/GitHowTo#what-should-i-do-if-im-in-a-bad-situation

https://stackoverflow.com/questions/9646167/clean-up-a-fork-and-restart-it-from-the-upstream

https://gist.github.com/CristinaSolana/1885435

  • Checkout upstream/master TO UPDATE
  • Fetch changes
  • Pull from upstream
  • Push to origin

checkout my master rebase from upsteam/master push to origin/master Feature Branch -> checkout and rebase

To roll back to an earlier commit on github: git push origin +0999ca8:master

How do I force “git pull” to overwrite local files? https://stackoverflow.com/questions/1125968/how-do-i-force-git-pull-to-overwrite-local-files I think this is the right way:

git fetch --all Then, you have two options:

git reset --hard origin/master OR If you are on some other branch:

git reset --hard origin/<branch_name> Explanation:

git fetch downloads the latest from remote without trying to merge or rebase anything.

Then the git reset resets the master branch to what you just fetched. The --hard option changes all the files in your working tree to match the files in origin/master

Maintain current local commits

[*]: It's worth noting that it is possible to maintain current local commits by creating a branch from master before resetting:

git checkout master git branch new-branch-to-save-current-commits git fetch --all git reset --hard origin/master After this, all of the old commits will be kept in new-branch-to-save-current-commits.

Uncommitted changes

Uncommitted changes, however (even staged), will be lost. Make sure to stash and commit anything you need. For that you can run the following:

git stash And then to reapply these uncommitted changes:

git stash pop

git config --global user.email "[email protected]" git config --global user.name "MizterB"

git init git remote add origin [email protected]:MizterB/<REPO_NAME>.git git add . git commit -m "Initial commit" git push -u origin master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment