Git cheatsheet¶
- Author:
GIT¶
See What Branch You’re On¶
Run this command:
git status
List All Branches¶
Note
The current local branch will be marked with an asterisk (*).
git branch
git branch -r
git branch -a
Create a New Branch¶
git checkout -b my-branch-name
You’re now ready to commit to this branch.
Switch to a Branch In Your Local Repo¶
Run this command:
git checkout my-branch-name
Switch to a Branch That Came From a Remote Repo¶
git pull
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¶
You’ll want to make sure your working tree is clean and see what branch you’re on. Run this command:
git status
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.
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 todo.
Delete Branches¶
git push origin –delete my-branch-name
git branch -d my-branch-name
git branch -D my-branch-name
Note
The -d option only deletes the branch if it has already been merged. The -D option is a shortcut for –delete –force, which deletes the branch irrespective of its merged status.
Tags¶
git tag -a nombre-del-tag id-del-commit
git tag -d nombre-del-tag
git tag o git show-ref –tags
git push origin –tags
git tag -d nombre-del-tag y git push origin
:refs/tags/nombre-del-tag.
Change remote origin¶
git remote add origin git@gitlab.com:ambagasdowa/mkforms.git
git remote set-url origin git@gitlab.com:ambagasdowa/mkforms.git