Skip to content

Instantly share code, notes, and snippets.

@achristodoulou
Created December 12, 2015 20:33
Show Gist options
  • Save achristodoulou/47ff5103660f01a1d63d to your computer and use it in GitHub Desktop.
Save achristodoulou/47ff5103660f01a1d63d to your computer and use it in GitHub Desktop.
Short tutorial with shell script that explains how git rebase works
#Lets initialize an empty repository
git init
#Then create a new file and commit
touch README.md
echo "Hello World" >> README.md
git add .
git commit -m "First commit"
#We need a new branch to work alone
git checkout -b feature
#Do your changes and commit them....
touch CHANGELOG.md
echo "World" >> CHANGELOG.md
git add .
git commit -m "Third commit"
#In the meantime another developer makes a commit to master branch
git checkout master
echo "World 2" >> README.md
git add .
git commit -m "Second commit"
#Now what? Hmm, instead of doing a merge and create a merge commit
#in git history I will do a rebase which will take all my commits
#and append them to git history and it will not create a merge commit
#and it will be more readable
git checkout feature
git rebase master
#Now I am ready to take my commits to master
git checkout master
git merge feature
#Check git history and you will see that my commits are the last one
#and not merge commit is shown...
git log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment