Skip to content

Instantly share code, notes, and snippets.

@Andreluizfc
Last active July 17, 2023 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Andreluizfc/73444db689e659276198d1dc1658013d to your computer and use it in GitHub Desktop.
Save Andreluizfc/73444db689e659276198d1dc1658013d to your computer and use it in GitHub Desktop.

GIT COMMANDS

Delete local branch:

git branch -d branch_name (--delete)

git branch -D branch_name (--delete --force)

Delete last commit from branch

Delete the most recent commit, keeping the work you've done:

git reset --soft HEAD~1

Delete the most recent commit, destroying the work you've done:

git reset --hard HEAD~1

Then Push force

git push origin branch_name --force

Rebase:

Rebase before push:

git stash save -> if you have changes in your branch
git checkout branch_to_rebase
git pull
git checkout old_branch
git rebase branch_to_rebase
git push -f
git stash pop

Rebase after commit and push:

git checkout branch_to_rebase
git pull
git checkout old_branch
git rebase -i branch_to_rebase
git push -f

Rebase to organize

git rebase --autosquash --interactive main

Show branches:

git branch -a (Local and Remote)

git branch -r (Remote)

Fetch all branches:

git fetch --all
git pull -- all

Prune not used branches

git fetch --prune

Clear .git folder

git verify-pack -v .git/objects/pack/pack_name.idx \
| sort -k 3 -n \
| tail -10

To see what each file is, run this:

git rev-list --objects --all | grep [first few chars of the sha1 from previous output]

One option is to use the bfg-repo-cleaner tool. Alternatively, you could do it manually following this git article, as outlined below:

git filter-branch --index-filter 'git rm --cached --ignore-unmatch *.mov' -- --all
rm -Rf .git/refs/original
rm -Rf .git/logs/
git gc --aggressive --prune=now
Then repeat with other types of files.

Then verify:

git count-objects -v

Your size-pack should be a lot smaller now.

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