DEV Community

Ruben Alvarado
Ruben Alvarado

Posted on

Set New Branch in Git

If you want to add a new feature to an app you have cloned. You can create a new branch for that feature following these git commands.

git switch -c <branch-name> // creates the branch
git add <file-or-folder>     // or use '.' to stage all changes
git commit -m "<commit-message>"
git push --set-upstream origin <branch-name>
Enter fullscreen mode Exit fullscreen mode

You can also simply try git push, in that case you will get a warning that the branch doesn't exist in remote yet and you receive a suggestion using the --set-upstream parameter. Instead of memorizing the last command with the parameter you can copy and paste the command that the terminal suggests.

And that it. Use this snippet to preserve working code in master and your new code in your feature or bug fix branch.

🤓Happy coding😎

Top comments (0)