- Git Cheat Sheet
- How to clean Git commit history
- How to fetch latest content from main repo to forked repo
Git Cheat Sheet
# Checkout a new branch
git checkout -b new-branch
# push new branch to remote
git push -u origin new-branch
git push --set-upstream origin new-branch
# fetch the latest changes from remote
git fetch origin
# Merge the latest main into your branch
git merge origin/main
How to clean Git commit history
# Create Orphan Branch
git checkout --orphan temp_branch
# Add Files to Branch and commit
git add -A
git commit -am "the first commit"
# Delete master Branch
git branch -D main
# Rename temp/Current Branch to master
git branch -m main
# Push Changes to repo as master
git push -f origin main
Original post: How to Delete Commit History in Github
How to fetch latest content from main repo to forked repo
Follow these steps to update your forked repository with the latest changes from the original (eg. main
or master
) repository.
1. Add the original repo as upstream
(only once)
git remote add upstream <original repo URL>
Skip this step if you’ve already added
upstream
. You can verify with:
git remote -v
2. Fetch the latest changes from the original repo
git fetch upstream
3. Merge or rebase changes into your local branch
Make sure you’re on your working branch (e.g. master
or main
):
git checkout master
git merge upstream/master
Optional: Use rebase for cleaner history:
git checkout main
git rebase upstream/main
4. Push the updated branch to your fork
git push origin main
Now your forked repository is up to date with the latest changes from the main/original repository.