Find some of the useful git commands for creating and managing a new branch in git/GitHub.
1. Create a New Branch in Git
You may need to create branch anytime during development for keeping your clean to your master branch. Usually, we create a new branch by copying the master or current branch code. Branches can be merged to master or other branches.
Remember to keep your master clean before creating a new branch. Commit and sync your uncommitted changes, if any in your local repository. Open your Git Shell and follow below git commands to create a new branch on your local machine:
$ git branch <name_of_your_new_branch>
Once your branch is created you will push the branch on github remote by using below commands
$ git push origin <name_of_your_new_branch>
2. Switch to your new branch
$ git checkout <name_of_your_new_branch>
3. List all branches created
$ git branch
4. Adding files/folders to branch
Now you may add some new files or folders to this branch. Either you may create a new file using your vim editor or you may paste the files and folders using your file explorer. When you want to commit something in your branch, be sure to be in your branch. Before committing you must all new files/folders using below command.
$ git add-A
$ git push origin <new branchName>
5. Delete a git branch
The first git command deletes the branch on your local file system and the second command deletes branch in github
$ git branch -d <name_of_your_new_branch> $ git push origin :<name_of_your_new_branch>