Skip to content

Instantly share code, notes, and snippets.

@Antarian
Last active October 22, 2020 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Antarian/579bd959f5c4229afb079c4955ad84ff to your computer and use it in GitHub Desktop.
Save Antarian/579bd959f5c4229afb079c4955ad84ff to your computer and use it in GitHub Desktop.
Git commands

Cleaning

Show informations about remote branches:

git remote show origin

Stop tracking deleted remote branches:

git remote prune origin --dry-run

Remote tracking

Verify origin and upstream setup:

git remote -v

If upstream is missing, setup:

git remote add upstream git@bitbucket.org:some-gatekeeper-maintainer/some-project.git

Collect changes of upstream repository:

git fetch upstream

Checkout main branch (master):

git checkout master

And continue usual workflow:

git pull upstream master || $ git merge upstream/master || $ git rebase upstream/master

Lost and found

Look to log for what you lost:

git reflog

Create new branch from what you found:

git checkout -b branch-name 70b3696

Unstage all local changes

To keep changes:

git reset HEAD

To remove everything not commited permanently:

git reset --hard HEAD

To reset changes to specific origin branch:

git fetch origin
git reset --hard origin/master

remove cached files if change in .gitignore is not taken into account

git rm -r --cached .
git add .

change info about previous commits

start interactive rebase as many commits backward as you need

git rebase -i HEAD~8

and in message alter details of specific commits with command on next line after wanted commit pick

pick a37d264 PHPSPEC-1 Install
exec GIT_COMMITTER_DATE="Thu Jan 9 18:12:51 2020 +0000" git commit --amend --no-edit --date "Thu Jan 9 18:12:51 2020 +0000" --author="Peter Labos <peter.labos@gmail.com>"

this change may require force push

Only change owner of commits

Use last coorrect commit hash

git rebase -i f10cc70c049a297bbd05552c62d591ff96c41836 -x "git commit --amend --author 'Peter Labos <peter.labos@gmail.com>' -CHEAD"

Remote tracking of all available branches

git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git pull --all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment