I have cloned project from repo and I need to create branch and in that branch do my changes. After that I need to push that branch on repo. How to do this ? I am sorry, I am new to git ?
New Branches The git branch command can be used to create a new branch. When you want to start a new feature, you create a new branch off main using git branch new_branch . Once created you can then use git checkout new_branch to switch to that branch.
You can create a new branch called my-work
(based on your current commit) and switch to that branch with:
git branch my-work
git checkout my-work
Or, as a shortcut for those two commands, you can just do:
git checkout -b my-work
To push that branch to the repository that you cloned from, you should do:
git push origin my-work
origin
is a nickname for the repository you cloned from. It's known as a "remote", in git terminology. Update: a clarification due to Michael Minton's helpful comment above: this will push your my-work
branch to a branch called my-work
in the remote repository, creating it if necessary - if you meant something different, it would be best to edit your question to clarify that point.
The first time you do that push command, you may want to do git push -u origin my-work
, which sets configuration options that make the branch my-work
in the origin
repository considered as the default "upstream" branch for your my-work
branch. (You don't need to worry about that for the moment if you're new to git, but it will mean that git provides more helpful status information and various commands have more useful default actions.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With