Skip to content

Instantly share code, notes, and snippets.

@mmastoras
Last active June 11, 2021 18:59
Show Gist options
  • Save mmastoras/2039097 to your computer and use it in GitHub Desktop.
Save mmastoras/2039097 to your computer and use it in GitHub Desktop.
some helpful git commands
setup local branch tracking a remote feature branch
====================================================
git checkout -b <feature branch name> origin/<feature_branch_name>
create new feature branch
=========================
git checkout master
git checkout -b <feature branch name>
create a new local branch tracking a remote branch
==================================================
git checkout -b <feature_branch_name>
git push -u origin <feature_branch_name>
push/create new feature branch
==============================
get checkout <feature branch name>
git push origin <feature branch name>
remove remote branches
======================
git push origin :<feature branch name>
remove local branches
=====================
git branch -D <local branch name>
merging master into local feature branch
========================================
git checkout master
git pull
git checkout <local branch name>
git merge master
git push
merging local feature branch into master
========================================
git checkout <local branch name>
git pull
git checkout master
git pull
git merge <local branch name>
git push
resolving merge conflicts
=========================
git mergetool - hit return twice, opens up the merge tool
resolve merge by choosing each
MergeTool Save
MergeTool Quit
Answer Y
add/commit the changes to complete the merge than proceed to push
revert last commit - assumes it wasn't pushed
=============================================
git reset --soft HEAD~1
revert last commit - assumes it was pushed
==========================================
git revert HEAD # this will create a new commit that backs out the old one, you'll need to commit and push
squash all commits on a branch into 1
======================================
git log --graph --decorate --pretty=oneline --abbrev-commit # show all commits
git rebase -i HEAD~<# of commits from top to merge into 1>
git rebase -i HEAD~<sha of the commit that you originally branched from>
@mmastoras
Copy link
Author

checkout out particular commit

git checkout
git checkout -b

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