Skip to content

Instantly share code, notes, and snippets.

@kakashysen
Last active September 23, 2016 14:12
Show Gist options
  • Select an option

  • Save kakashysen/6c9a5ef1fc4248b60d5b to your computer and use it in GitHub Desktop.

Select an option

Save kakashysen/6c9a5ef1fc4248b60d5b to your computer and use it in GitHub Desktop.
How to with Git

Tricks for how to use git

How to change or move to an specific branch

  • git checkout <branch-name>

Example: git checkout development

How to update branch from web repository Hacer un pull de development desde upstream development

  1. git checkout <branch-name>
  2. git pull <remote> <branch-name>

How to change to other branch

git checkout master

How to pull a branch from a specific remote

git pull upstream master

How to compare changes between two branches local to remote

git diff <local branch> <remote>/<remote branch>

TAGGING

How to fetch all tags from specific remote

git fetch <remote> --tags

Example git fetch upstream --tags

How to create tags

git tag <tag_name>

Example git tag v1.2.0

How to push tags to repository

git push origin --tags

How to push specific tag to repository

git push origin <tag_name>

Example git push origin v1.5

How to delete an specific tag in local repository

- git tag -d <tag_name>

Example - git tag -d v2.5

How to delete a tag from a specific remote

git push <remote> :<tag_name>

Example git push upstream :v2.5

How to track a local branch

git branch -u <remote>/<branch>

Example git branch -u origin/my-branch

How to change to branch than not is in my local repository

git checkout -b <branch-name> <remote>/<branch-name>

Example git checkout -b other-branch origin/other-branch

If you want to track a remote branch add --track at the end of command

Example git checkout -b other-branch origin/other-branch --track

How to fetch a specific branch from specific remote

git fetch <remote> <branch-name>

Example git fetch origin developer

How to reset all changes stuff from your local repo. no need to clone it again

git fetch origin && git reset --hard origin/master && git clean -f -d

How to merge a branch into another branch

  1. First go to the base branch where you want to merge git checkout <branch-base>
  2. Now run the next command to merge git merge <branch-to-merge>

How to undo the last commit

git reset --soft HEAD~

How to add more comments to the last commit

git commit --amend

How to add alias in git

  • checkout -> co

$ git config --global alias.co checkout

  • branch -> br

$ git config --global alias.br branch

  • commit -> ci

$ git config --global alias.ci commit

  • status -> st

$ git config --global alias.st status

How to rename local branch

git branch -m <oldname> <newname>

Example git branch -m mi-branch my-branch

How to rename current branch

git branch -m <newname>

Example git branch -m my-new-branch-name

RENAME

How rename a current branch

git branch -m <newname>

Example

git branch -m zonbie-branch

How to rename a branch

git branch -m <oldname> <newname>

Example git branch -m zombi-branch zombie-branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment