Git branch- the key ingredient in development

Rhett Haynes
3 min readApr 30, 2021

--

“Branch early and branch often” is the motto we should all develop by. It allows you to work in parallel with other team members on the same project. Git is super lightweight, making branching operations nearly instantaneous, and switching back and forth between branches generally fast. Git encourages workflows that branch and merge often, even multiple times in a day.

To create a new branch, you can use 2 of the following commands:

  • git branch “name of the new branch”
  • git checkout -b “name of the new branch”

Now if you look in “git — help”, you will see “git checkout” has been replaced with “git switch” as checkout is a legacy command that can be still used if you’re comfortable with it. I recommend using “git checkout” because this command is used in other commands that “git switch” is only used to switch to another branch. When you use the second command, it will create a new branch and switch to that branch automatically.

Creating a new branch with git branch command.
Creating a new branch with git checkout -b command.

To delete a branch, you can use the following command:

  • git branch -d “name of the branch to delete”
Deleting a branch

Next, to merge a branch into another branch, you will need to make sure to add new changes and commit them. Once that is done, switch to the branch you will be merging with. Then, use the following command to merge:

  • git merge “name of the branch to merge with”
Added, committed, then merged.
Merge completed.

Finally, push your new changes to the server to allow your team members to work off of what you worked on.

Pushed the merged files to the github server.

We will stay with Git branches and delve into a few more topics that may come up in the future that we may need to address. Until next time …

--

--

Rhett Haynes
Rhett Haynes

Written by Rhett Haynes

Learning to become a Unity game developer.

No responses yet