Git Branches Flashcards
Command to create a new branch and switch to that branch?
git checkout -b <branch_name></branch_name>
what is a branch in git?
A branch is basically a pointer to the last commit. barnaches are nothing more but a pointer to a certain commit
command to create a new branch
git branch <branch_name></branch_name>
Command to switch to another existing branch
git checkout <branch_name></branch_name>
Command to delete a branch
git branch -d <branch_name></branch_name>
Command to list all branches
git branch
What is a HEAD in git branches?
A HEAD is where you are right now in the git repository. HEAD points to the last commit in the branch you are currently on. When you switch branches, the HEAD moves with you.
where does git by default point to?
git always points to the last commit of the currently checked out branch
Lets say you are in sarah branch, and made some changes, and all of them are committed. Now we want to merge that with the master branch, how do we do it?
First checkout to master branch
git checkout master
Then use the command -
git merge sarah
Two types of merges git can perform?
fast forward merge
no fast forward merge
what is a fast forward merge?
A fast-forward merge can happen when the current branch has no extra commits compared to the branch that we’re merging. This type of merge doesn’t create a new commit, but rather merges to commits on the branch that we’re merging right into the current
branch.
What is no fast forward merge/?
Git will perform a no-fast-forward merge. With a no-fast-forward merge, Git creates a new merging commit on the active branch. The commits parent commit to both the active branch and the branch we want to merge.