Using Git to implement a new feature/change without affecting the main branch

What is Git &why use it?

Git is an Open Source Distributed Version Control System. it makes it easy to track changes to file and revert back to them incase a need arises.
This blogs aim is to illustrate on how to use git branch feature in order to make changes to your software without affecting the main branch.

Steps to follow

Clone a repository

//Clone the repository to your local Machine
git clone repository_url
//remember to replace the 'repository_url' with your own repo link

Create a new branch

//check for other available branches on the local repo
git branch
//create a new branch called "awesome-feature" on the local repo
git branch -b awesome-feature
//confirm it been created
git branch
//check out to the new branch
git checkout awesome-feature
//Altenatively you could do all that in one command
git checkout -b awesome-feature

Add new Files to the New Branch

You can makes changes to your awesome-feature files and commit the changes on the branch

//to check untracked files 
git status
// to track all changes made
git add .
//to track only a single file 
git add file_name
//save changes made in the local repo
git commit -m "awesome-feature first commit"
//verify the changes
git status

After saving all the changes on the local repo, its time to push them to the remote repo approval required.
If working alone and you had the merges; **skip the push changes to Remote repo and merge the branch **

Push changes to the Remote repo

//verify your  remote URL
git remote -v
//to create a new feature branch on remote repository and push changes to that branch
git push origin awesome-feature

Finally you have made changes locally and pushed the to the remote repo branch without affecting the master.
The next step in a work environment is to wait for the Supervisor to approve before we can merge the changes of the awesome-feature branch to the master.
In a personal development environment the next step is to run the merge request.

Merge request

The command merges the branch to the master.

//checkout to master
git checkout master
//merge branch to master
git merge awesome-feature -m "merge"

Conclusion:

As illustrated above, one can do their work without affecting anyone or breaking production.

freecode Camp - Git Tutorial
Git Cheatsheet