Skip to content

Instantly share code, notes, and snippets.

@zsitro
Last active November 29, 2017 08:35
Show Gist options
  • Save zsitro/e1b21c60d570dcb83e88 to your computer and use it in GitHub Desktop.
Save zsitro/e1b21c60d570dcb83e88 to your computer and use it in GitHub Desktop.
Git things

Remove all deleted files from index when commit changes

git add -u

Add everything to a commit (also deletes)

This is most useful when your terminal is not in the root and you don't want to change dir just to commit

git add :/ -u

Hotfixing

git checkout master
git checkout -b hotfix
git push origin hotfix
YOU FIX YOUR PROBLEM HERE
git add -A
git commit -m "Fixed typo."
git push
git checkout develop
git merge hotfix
git checkout master
git push origin :hotfix
git branch -D hotfix

Mark tracked file unchanged

Tipically database config files, .htaccess, etc.

git update-index --assume-unchanged <file>
git update-index --no-assume-unchanged <file>

Forgot to change branch before editing files on current branch?

git stash
git checkout other-branch
git stash pop

Create feature-branch from uncommited files

git checkout -b user/feature
git add .
git push --set-upstream origin user/feature

Undo a pull which caused conflicts

git reset --hard ORIG_HEAD

Thin clone

git clone ... --depth=1

Undo last commit

git reset --soft HEAD~1 

Revert state to older version

Just to check something

git checkout <hash-of-commit>

Update feature branch with fresh develop content

git checkout user/feature
git pull --all
git rebase develop

And if you need to fix merge conflicts: do the fixes, then don't commit, just git add the files, then git rebase --continue. If you already commited the merge then you can backup with git reset HEAD~ and then git add and then git rebase --continue.

Delete branch

git push origin :zsitro/responsive
git branch -d zsitro/responsive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment