Tag Archives: Git

Git: My aliases

Every time you start a new assignment on a new computer all your aliases are gone. I’ll put them here for easy access, and if someone likes them they can use them too 🙂

git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.last 'log -1 HEAD'

Tested with Git v 2.24.3 on OSX and Linux

Git: “You can only push your own commits in this repository” – when there actually is a problem

I ran into this recently by creating a new Bitbucket repository when having a spelling error in my mail address in settings. I got this error:

remote: You can only push your own commits in this repository
remote: Commit 85eb7acbf42a14b9 was committed by Niklas Ottosson (username) <niklas@worldwideweeb.com>

In the commit 85eb7acbf42a14b9 (initial commit of the new repository) my mail was niklas@worldwideweeb.com when it should have been niklas@worldwideweb.com (only one ‘e’ in ‘web’)

To fix this we need to make sure we have the correct mail address in global settings:

git config --global user.email niklas@worldwideweb.com

and then reset the author of the initial commit

git commit --amend --reset-author --no-edit

This will now replace the previous author with me, and since I now have the correct spelling the commit will be “fixed”

Tested with Git 2.24.3

Git: “Squash” your commits – alternative solution

Sometimes you will have a pull request that is full of merge commits mixed with regular commits. These branches are a little tricky to squash. I’m here going to show a trick that I sometimes use.

Stand in your pull request branch and run:

git reset --soft origin/master

This resets us back to master but keeps all our changes in staged, ready for us to commit in to one new commit:

git commit -m"My one commit message for all changes"

After this we need to replace all the commits in our pull request with the new one we have in our local

git push -f

We should now have only one commit in our pull request

Tested on Git v2.24.3 and OSX 10.15.6