If you are asking yourself how to copy changes from one branch to another, you are probably in the right place. Many posts out there suggest a git merge or git rebase which is also fine, but not the proper way if you ask me.
Prerequisites
- Git
Solution
Step 1. As with the rest of mine Git tutorials first find the commit ID (hash) you want to copy from by using my personal favorite command: git log
. Or just scroll down the GitHub history.
Step 2. Checkout the branch which you want to “paste” the commit. For instance:
git checkout main
Step 3. Apply the commit:
git cherry-pick <commit-SHA1>
The command (cherry-pick) creates a new commit unless you pass the --no-commit
option. Cherry picking commits in Git.
Conclusion
To find more neat Git commands and hacks, simply browse the Git category. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.