Git¶
Publish¶
Pull + Rebase¶
Squash¶
Squash the last 3 commits
If pushed to the remote branch, then you should push
Rebase Feature Branch onto latest Main Branch¶
First, make sure you are currently on your feature branch, then fetch the latest changes from the remote repository:
Next, rebase your feature branch onto the updated main branch:
If conflicts occur during the rebase, resolve them manually, stage the resolved files, and continue the rebase process:
After the rebase is completed, push the updated branch to the remote repository. Since rebasing rewrites commit history, use a safe force push:
If you need to stop the rebase process at any point, you can abort it:
Note: Avoid rebasing branches that are shared with other developers. Instead, consider merging the main branch into your feature branch by using:
Delete local branches that are not used in remote¶
Detail
This command sequence does the following:
git fetch --prune: Fetches the latest changes from the remote repository and removes any references to branches that have been deleted on the remote.git branch -vv: Lists all local branches along with their tracking information and the latest commit message. thengrep ': gone]'filters out branches that are marked as "gone", which indicates that the corresponding remote branch has been deleted. Finally,awk '{print $1}'extracts the branch names from the filtered list, andxargs git branch -ddeletes those local branches that are no longer present on the remote repository.
Worktrees¶
Create a worktree folder under <path/to/worktree> and create a branch named <branch-name> from main branch.
Move worktree folder from <path/to/old/worktree> to <path/to/new/worktree>
To show worktree list, in main worktree, run:
In worktree folder, run:
Warning
同一個 branch 不能同時在兩個 worktree 被 checkout
To prevent a working tree from being pruned:
To allow working tree to be pruned, moved or deleted:
To remove a working tree: