Git is the most widely used versioning control system for tracking source code files. It contains multiple branches that allow users to work on different code versions simultaneously. Additionally, feature branching also plays a significant role. It permit multiple teams of developers to participate in a master branch within a central code base.
This post will demonstrate the complete workflow of the Git feature branch.
What is the Git Feature Branch?
When programmers write code while working on Git, they tend to do so on Git branches. It becomes challenging to add, change, or remove code when several developers are working on the same branch without their efforts overlapping or overwriting one another’s modifications. A Git “feature” branch is used when a developer wants to create a copy (1:1) of the “master” branch from which they can make changes. The easiest way to visualize it is as a tree with a trunk that serves as the master branch and branches that are copies of other codebases.
Git Feature Branch Workflow
To combine all the modifications from a local branch into a remote “feature” branch, check out the provided instruction:
- Navigate to the Git root directory.
- List all Git local branches.
- Run the “git checkout -b” command to create a feature branch.
- Verify the newly created feature branch.
- Execute the “echo” command to create and edit the file.
- Track the newly generated file into the staging environment with the help of the “git add” command.
- Run the “git commit -am” command to commit changes.
- Lastly, push the “feature” branch to GitHub and verify it.
Step 1: Redirect the Git Repository
First, redirect the Git root directory using the “cd” command and navigate to it:
Step 2: List Git Branches
Run the “git branch” command to view/check the existing local branch:
Step 3: Design a Feature Branch
Run the “git checkout” command along with the “-b” option for making and navigating to the new branch:
It can be observed that we have successfully created and switched to the “feature” branch:
Step 4: View Current Git Branch
Run the below-stated command to view the current working branch:
According to the below-given output, the asterisk “*” beside the “feature2” indicates that it is the current working branch:
Step 5: Create and Edit the File
Utilize the “echo” command to make and edit the file simultaneously:
Step 6: Track File to Staging Environment
To track the newly created file from the working area to the staging index, run the provided command:
Step 7: Commit Changes
Next, save the changes through committing, execute the “git commit” command along with the “-am” option for adding all changes tracked as well as untracked:
Step 8: Push Feature Branch to GitHub
To push the feature branch to GitHub, the “git push” command can be used with the remote and branch name:
After that, navigate to the GitHub remote repository where changes have been pushed. And verify through the “features2 has …..” message:
That’s all! We have explained the Git feature branch workflow.
To follow the Git feature branch workflow, initially, navigate to the Git root directory. Next, list all existing local branches. Run the “git checkout -b” command to create and switch branches simultaneously. Then, use the “echo” command to create and update the file. Track changes by utilizing the “git add” command and save them to the Git repository by running the “git commit -am” command. Lastly, push the local changes to the remote server. This post illustrated the complete workflow of the Git feature branch.