The fundamental means of launching a separate line of development in a software project is a branch. A branch can be used to keep an old version of the project alive. A branch can be used to encapsulate a development phase or the development of a single feature or bug fix.
Branch names
Branch names are pretty arbitrary but there are many characters not allowed or not allowed at the beginning or end.
Using Branches
There can only be one current branch within the git repository at any given time. The current branch determines which files are checked out in the working directory. It is also often an implicit operand in Git commands (such as the target of a merge).
The most recent commit on a branch is called the tip or {{c1::head}} of the branch. A branch/branch name can be thought of as a pointer to a particular {{c1::commit}}. To introduce a new branch to the repo within checking it out as the current branch, use the git branch command. This command also lists the branch names found in the repo if not passing a branch name argument. The git show-branch also can be used to view the branches and provides more detailed output than git branch.
Checking out Branches
The git checkout command changes the current branch. If you have local changes, Git will issue an error message and let you know that you need to commit you changes first (adding it to the index is not sufficient). You can use the -f option to tell Git to check out the other branch anyway which will overwrite your local changes.
Detached HEAD Branches
If you check out a random commit, Git creates a sort of anonymous branch for you called a {{c1::detached HEAD}}. It also does this when starting a git bisect operation or the git submodule update command.
Deleting Branches
The git branch command with the -d or -D option can be used to delete a branch. If deleting the branch were to delete a commit that would be lost since it had not been merged into main, Git will issue an error when using -d but the -D option will override Git's safety check. When a branch is deleted, the branch name is gone. It may be possible to recover the commits (git reflog would be the command to get that started) but commits with no references to them will eventually be collected as garbage.
Article notes
What is the fundamental means of launching a separate line of development in a software project?
A branch
What determines what files are checked out in the working directory of a Git repository?
The current branch
How many current branches can there by in a Git repository at any one time?
1
What is the most recent commit on a branch called?
The head
What is the command to introduce a new branch to the repo?
git branch
What does the git branch command do when used with no arguments?
Lists the branch names
What git command can also be used to view the branches (like git branch does) but provides more detailed output?
git show-branch
What is the Git command that changes the current branch?
git checkout
What is the anonymous branch Git creates for you when you check out a random commit called?
A detached HEAD
What options can be used with the git branch command to delete a branch?
-d or -D
If you delete a branch with the -D option and then realize you want to get a commit that is gone back, where should you turn?
The reflog
A branch/branch name can be thought of as a pointer to a particular [...].
A branch/branch name can be thought of as a pointer to a particular commit.
If you check out a random commit, Git creates a sort of anonymous branch for you called a [...].
If you check out a random commit, Git creates a sort of anonymous branch for you called a detached HEAD.
The most recent commit on a branch is called the tip or [...] of the branch.
The most recent commit on a branch is called the tip or head of the branch.