Git is a VCS (Version Control System) used by many, including me.
Writing code on a new branch is a great way to experiment with ideas while being able to keep track of your revisions. You might delete an entire branch because your idea didn’t work or you might merge the branch back into the main branch.
git checkout -b branch # create a new branch git checkout main # switch to a different branch
Merging allows you to join two or more histories together.
git checkout develop git merge --no-ff feature/name # no fast-forward - useful for maintaining a branch topology git commit -m "message [#30]"
Sometimes my branches have too many commits. You can use
--squash to combine
all of the commits into one when merging.
git checkout feature/name git merge --squash experiment/idea git commit -m "implement idea [#24]"
We all make mistakes and sometimes we need to reset a branch to a previous state.
git reset --hard HEAD # reset the files to the last commit git reset --hard COMMIT_HASH # reset the files to a specific commit git reset --hard origin/master # reset the files to a remote branch