These are a view things that i had looked up to solve some problems and i plan to update this post regularly…
To push a new branch to remote
git push origin new_branch |
git push origin new_branch
To delete a remote branch
git push origin :new_branch |
git push origin :new_branch
To push new tags
To delete a remote tag
git tag -d 12345
git push origin :refs/tags/12345 |
git tag -d 12345
git push origin :refs/tags/12345
To reset a local branch to exactly match a remote branch
git fetch origin
git reset --hard origin/master |
git fetch origin
git reset --hard origin/master
To abort a rebase
Changing the origin of your git repository (relocate the repository)
git config remote.origin.url [new origin url] |
git config remote.origin.url [new origin url]
How do I make git ignore mode changes (chmod)?
git config core.filemode false |
git config core.filemode false
Delete the last commit if it is not pushed yet:
Remove file from repository but not from filesystem (in case you’ve ignored a file but don’t want to delete it)
git rm --cached Foobar.java |
git rm --cached Foobar.java
Short log (oneline), including sha and date
git log --pretty=format:"%h %ad%x09%an%x09%s" --date=short |
git log --pretty=format:"%h %ad%x09%an%x09%s" --date=short
Count commits by author:
Display the first n commits:
git log --pretty=format:"%h %ad%x09%an%x09%s" --date=short --reverse | head -20 |
git log --pretty=format:"%h %ad%x09%an%x09%s" --date=short --reverse | head -20
Merge a branch but don’t commit the merge yet (and avoid fast-forwards):
git merge --no-commit --no-ff theAwesomeFeatureBranch |
git merge --no-commit --no-ff theAwesomeFeatureBranch
List all files changed since commit:
git git diff --name-only COMMIT_ID_OR_WHATEVER_COMMITISH |
git git diff --name-only COMMIT_ID_OR_WHATEVER_COMMITISH
This one is useful, if you did a lot of amending to an old commit and want to restore it’s date order for your inner monk:
Do an interactive rebase, edit the commit in question with “e” or “edit”, so that you can amend it again and then continue rebase:
git rebase -i <ref>
git commit --amend --reset-author --no-edit
git rebase --continue |
git rebase -i <ref>
git commit --amend --reset-author --no-edit
git rebase --continue
Or you could move around the commit during your rebase as well, if it isn’t your last commit.
Group commits by author:
Reduce the repositories database size:
git reflog expire --all --expire=now
git gc --prune=now --aggressive |
git reflog expire --all --expire=now
git gc --prune=now --aggressive
(See this answer)
Pushes a subtree onto a different branch (“dist” being the subtree here):
git subtree push --prefix dist origin gh-pages |
git subtree push --prefix dist origin gh-pages
Create a new branch with all the content from the parent but without commits:
git checkout --orphan public |
git checkout --orphan public
Last update: 2019/01/06
Filed in English posts, Shortcuts
|