This tutorial demonstrates how to use Git's stash and squash features to manage changes across different branches and combine multiple commits into one when merging.
By following these steps, you can efficiently manage changes across branches and keep your commit history clean by squashing multiple commits into one when merging.
- Git installed on your system.
- Basic understanding of Git commands and concepts.
mkdir sample_repository
cd sample_repository
git init
echo "Initial Content" > file.txt
git add file.txt
git commit -m "Initial Commit"
echo "More Changes" >> file.txt
git stash save "New Changes"
git checkout -b new-feature-branch
git stash apply
git add file.txt
git commit -m "First change in new-feature-branch."
echo "Even more changes." >> file.txt
git add file.txt
git commit -m "Second change in new-feature-branch."
git checkout main
git merge --squash new-feature-branch
git commit -m "Merged new-feature-branch with squashed commits."