Skip to content

Instantly share code, notes, and snippets.

@deanpanayotov
Last active November 25, 2015 16:20
Show Gist options
  • Save deanpanayotov/943b7c9e13ebd03b879c to your computer and use it in GitHub Desktop.
Save deanpanayotov/943b7c9e13ebd03b879c to your computer and use it in GitHub Desktop.
git-cheatsheet
Create a feature branch:
git checkout -b feature_branch develop
git push origin feature_branch
Merge a feture back to develop:
git checkout develop 
git merge --no-ff feature_branch
git branch -d feature_branch
git push origin develop
Revert a staged file to unstaged:
git reset HEAD file
Revert all files from staged to unstaged:
git reset HEAD
Clear local (unstaged) changes:
git clear -d -f
git chekcout .
Revert a local commit back to staging:
git reset --soft HEAD~1 
Delete a remote branch:
git branch -d branch_name
git push origin :branch_name
Move commits to different branch (from develop):
git checkout develop
git branch new_branch
git checkout new_branch
git push --set-upstream origin new_branch
git checkout develop
git reset --hard a1b2c3d4 # to the commit you want
gut push --force
Check whats stashed:
git stash show -p stash@{0}
Changing the remote:
git remote -v
git remote set-url origin https://github.com/USERNAME/OTHERREPOSITORY.git
git remote -v
Renaming a branch:
git branch -m feature-old feature-new
git push origin :feature-old
git push origin feature-new
Merging with conflicts:
git merge --no-ff <branch>
#option 1: merge manually
#option 2: use the changes from the destination branch
git checkout --ours -- <filename>
#option 3: use the changes from the origin branch
git checkout --theirs -- <filename>
# add and commit
git add <filename>
git commit -m "Merge message"
Ammend commit message
git commit --amend -m "New commit message"
Find common ancestor
git merge-base --octopus <sha1> <sha1>
Rebase: put a commit between other commits
git checkout <branch>
git checkout <sha1>
git checkout -b <temp>
git add
git commit -m <message>
git rebase <temp> <branch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment