Skip to content

Instantly share code, notes, and snippets.

@woblerr
Last active June 23, 2021 07:32
Show Gist options
  • Save woblerr/ee3434ee03c953b7fad8ef5327d5a662 to your computer and use it in GitHub Desktop.
Save woblerr/ee3434ee03c953b7fad8ef5327d5a662 to your computer and use it in GitHub Desktop.
Useful GIT commands

Reset origin to commit

git log
git reset --hard <commit-hash>
git push --force origin master

Add images to README.md

git checkout --orphan images
git rm -rf .
cp /path/to/the/image/image.jpg .
git add .
git commit -m "Add image.jpg into images branch"
git push origin images:images
git checkout master

Edit your README.md and add:

![alt text](../images/image.jpg?raw=true)

or full link (not recommended):

![alt text](https://github.com/YOUR_ACCOUNT_NAME/REPOSITORY_NAME/blob/images/image.jpg)


Show last 10 commits in table format

git log --pretty=format:"%h - %an, %ar : %s"|head

Merge all commits in branch into one

git checkout master
git merge --squash somefeature
git commit -m 'merged somefeature'
git push

Rename remote branch

git branch -m old new   
git push origin :old
git push --set-upstream origin new

Delete local branches that do not exist remotely

git checkout master; git fetch -p; git branch -vv | grep ": gone]" | awk '{ print $1 }' | xargs git branch -d

Delete remote tag

git push --delete origin tag_name

Remove file from all commit

git filter-branch --prune-empty --tree-filter 'rm -f FILE' HEAD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment