I use git almost daily so I don't really need my cheat-sheet anymore, but there are always instances that call for uncommon scenarios.
Taking note of these, so I don't have to dig for them the next time they're needed.
Stuff that got added after git add filename
git cherry -v
git reset --soft HEAD~;
If you committed a mistake to the repo that shouldn't stay in the history; a hard reset can clean it up - providing it's executed rapidly. If other systems/users have already received this commit, this will cause a mess.
For use in situations where you know nobody pulled, yet:
git log
and get the commit hash of the commit you want to return to (delete everything else after)Reset it:
git reset --hard [commit hash]
Force push it to the repo:
git push -f
All should be well
git push
This error:
Pushing to git@bitbucket.org:username/repo.git
Forbidden
fatal: Could not read from remote repository.
typically occurs when Bitbucket doesn't find the key it expects to see. (id_rsa, usually)
In your local ~/.ssh/config
:
Host bblocal
HostName bitbucket.org
IdentityFile ~/.ssh/keyname
IdentitiesOnly yes
In the repo's .git/config
:
git@bitbucket.org:username/repo.git
change bitbucket.org
to your alias: bblocal
From:
url = git@bitbucket.org:username/repo.git
pushurl = git@bitbucket.org:username/repo.git
To:
url = git@bblocal:username/repo.git
pushurl = git@bblocal:username/repo.git