Git
Create a Branch
List all your branches:
Create a New Branch
1
| git checkout -b new-branch-name
|
Or, checkout the branch you want to use:
1
| $ git checkout <feature_branch>
|
Confirm you are now working on that branch:
If your local branch already exists on the remote, run this command:
If your local branch does not exist on the remote, run either of these commands:
1
| git push -u origin my-branch-name
|
Merge a Branch
Check working tree is clean and see what branch you’re on
Check out the branch that you want to merge another branch into (changes will be merged into this branch, for example master).
Merge another branch into the current branch:
1
| git merge my-branch-name
|
Delete branch
1
| git branch -d <feature_branch_name>
|
Remove all previous commits
Checkout
1
| git checkout --orphan latest_branch
|
Add all the files
Commit the changes
1
| git commit -am "commit message"
|
Delete the branch
Rename the current branch to main
Finally, force update your repository
1
| git push -f GitHub main
|
Git: How to Handle Merge Conflicts