Home Git Basic
Post
Cancel

Git Basic

Git

Create a Branch

List all your branches:

1
$ git branch -a

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:

1
$ git branch 

If your local branch already exists on the remote, run this command:

1
git push

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

1
git status

Check out the branch that you want to merge another branch into (changes will be merged into this branch, for example master).

1
git checkout 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

1
git add -A

Commit the changes

1
git commit -am "commit message"

Delete the branch

1
git branch -D main

Rename the current branch to main

1
git branch -m main

Finally, force update your repository

1
git push -f GitHub main

Git: How to Handle Merge Conflicts

This post is licensed under CC BY 4.0 by the author.