Skip to content

Tools and Tips

Shankar Ganesh edited this page Apr 20, 2021 · 4 revisions

Git: Get Latest code

git fetch upstream main
git checkout <your-branch>
git pull upstream main --rebase
git push origin <your-branch> -f

Git: Clean up

git branch -D main
git checkout -b main upstream/main

Git: Squash commits

Follow the below steps to squash commits in a GitHub pull request:

git remote add upstream https://github.com/AlgoDataStructure/data-structure.git
git fetch upstream main
git checkout <your-branch-name> 
git rebase -i upstream/main
==
- Choose squash for all of your commits, except the first one 
- Edit the commit message to make sense, and describe all your changes >
==
git push origin <your-branch-name>  -f

Git Rebase

  1. Do not use the main branch

  2. Create a feature branch

    git checkout -b feature/<FEATURE_NAME>

  3. Fetch Latest upstream

    git fetch upstream main

    git pull upstream main --rebase

  4. Rebase the 5 commits

    git rebase -i head~5

  5. cherry pick the add header component

    git cherry-pick -n 8b5768943b653dba1bd9c4787c66196f37b0a79c

    git reset head --hard

  6. To merge the last two commits

    git reset --soft "HEAD^"

    git commit --amend

    git push -f

  7. delete all branch except main

git branch | grep -v "master" | xargs git branch -D
Clone this wiki locally