GIT Commands
GIT Commands
Preview changes,
before merging:
• Run this command (replacing my-branch-name with whatever name you want):
• git checkout -b my-branch-name
• You're now ready to commit to this branch.
1. To get a list of all branches from the remote, run this command:
• git pull
2. Run this command to switch to the branch:
• git checkout --track origin/my-branch-name
Push to a Branch
• If your local branch does not exist on the remote, run either of these commands:
• git push -u origin my-branch-name
• git push -u origin HEAD
NOTE: HEAD is a reference to the top of the current branch, so it's an easy way
to push to a branch of the same name on the remote. This saves you from
having to type out the exact name of the branch!
• If your local branch already exists on the remote, run this command:
• git push
Merge a Branch
1. You'll want to make sure your working tree is clean and see what branch you're
on. Run this command:
• git status
2. First, you must check out the branch that you want to merge another branch into
(changes will be merged into this branch). If you're not already on the desired
branch, run this command:
• git checkout master
• NOTE: Replace master with another branch name as needed.
3. Now you can merge another branch into the current branch. Run this command:
• git merge my-branch-name
• NOTE: When you merge, there may be a conflict. Refer to Handling Merge
Conflicts (the next exercise) to learn what to do.
Delete Branches