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>
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.
Use this snippet to preserve working code in master and your new code in your feature or bug fix branch.
Even an Easier way to get things done
Use an editor that supports VS Code extensions (like VS Code, Windsurf, etc). Get the git Conventional Branch extension

press ctrl+shift+p and select conventional branch. The wizard will ask you for
branch type: e.g. feature, fix
Ticker Number: using number identifiers for branches is frequent in development
branch name: your branch name
And that’s it. You have solutions if you have only CLI at your hands and also when you have a GUI editor.
🤓Happy coding, dev san😎






