Skip to content

Instantly share code, notes, and snippets.

@noemi-dresden
Last active January 9, 2019 15:44
Show Gist options
  • Save noemi-dresden/b48e262458e16e97ebf8e3b3f864d80a to your computer and use it in GitHub Desktop.
Save noemi-dresden/b48e262458e16e97ebf8e3b3f864d80a to your computer and use it in GitHub Desktop.
my most used git command

list remote

git remote -v

Reset a branch to remote

  1. git fetch origin
  2. git reset --hard origin/master

List branches

  1. remote git branch -r
  2. local git branch

Merge two branches

If you want to merge one of those remote branches on your local branch

  1. Go to your branch git checkout youbranch
  2. git merge origin/aRemoteBranch

If you want to merge one of your local branch on one of those remote branch, you need to create a local branch on top of said remote branch first

  1. git checkout -b myBranch origin/aBranch
  2. git merge aLocalBranch

Squash all commit to one

  1. Check out how many commit do you have with git log --graph --decorate --pretty=oneline --abbrev-commit
  2. run git rebase -i HEAD~(number of commits)
  3. just change the pick to f for the commit you do not want to pick
  4. save

Delete branch

Locally

  • git -d <branch-name> if the branch is not merge use -D

Remotely

  • git push origin :<branch-name>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment