master
is the source of truth and should be production-ready at all timesfeature
branches track work in progress and should be short-livedgit log
tells the story of our product and should be lineargit
is installed on your machinegit clone https://github.com/simon-parker/git-workshop
cd git-workshop
git log
outputgit log --oneline --decorate --all --graph # aka `git lola`
HEAD
is your current location in the repository(master, branch)
show your local branches/tags.(origin/master, origin/branch)
show your remote tracking branches/tags.git checkout <commitish>
<commitish>
can be a number of things, including:
git checkout <commit-hash>
git checkout <branch-or-tag-name>
git checkout <commitish>~1
git checkout <commitish>~
Try to solve the puzzle as efficiently as you can!
cd puzzles/checkout-them-all
source init
git add .
git add "src"
git add "*.sh"
git add "*/test/*"
git commit -m "commit message"
git commit --amend -m "amended commit"
git checkout -b new-branch
The new branch will appear at HEAD
cd puzzles/branch-gardening
source init
What situation led to this branching?
digraph hierarchy {
nodesep=0.5 // increases the separation between nodes
node [shape=box, style=rounded]
//rankdir=LR;
master, feature [style="square", color="red"]
feature -> "feature commit" -> "shared commit"
master -> "master commit" -> "shared commit"
}
git checkout feature-branch
git rebase master
digraph hierarchy {
nodesep=0.5 // increases the separation between nodes
node [shape=box, style=rounded]
//rankdir=LR;
master, feature [style="square", color="red"]
feature -> "feature commit" -> "master commit" -> "shared commit"
master -> "master commit"
}
✍️ Rebasing makes our history easy to understand by making it linear!
✍️ We are not done until our changes are on master
, the source of truth!
git checkout master
git merge feature
digraph hierarchy {
nodesep=0.5 // increases the separation between nodes
node [shape=box, style=rounded]
//rankdir=LR;
master, feature [style="square", color="red"]
feature, master -> "feature commit" -> "master commit" -> "shared commit"
}
✍️ Once our changes are on our source of truth, we should delete our short-lived feature branch.
git checkout master
git merge feature
git push master
git branch -D feature # delete local branch
git push --delete feature # delete remote branch
# delete any remote tracking branches
# others have deleted with git push --delete
git fetch -p
cd puzzles/rebase-madness
source init
-
shortcutLike bash
, Git will treat a -
as an alias for your previous location in the tree
It works with git checkout
, git rebase
and git merge
!
git checkout feature-branch
# ... do some work
git checkout master
git pull -r
git checkout -
git rebase -
git checkout -
git merge -
git push
It's time to bring together everything we learned and go through a full day in the life of a pair!
cd puzzles/day-in-the-life
source init
🙏 In the spirit of continuous improvement, please send me an e-mail with the following feedback:
😎 That's all, folks! 😎