Wednesday, 30 June 2021

Various git-related problems and tricks

Today some notes about git tips and tricks, which I often use and regularly forget.

They're not very "pro", just a few things I personally happen to find useful.

Aliases

If you use git from command line, it's helpful to define short aliases for commands like git checkout, git branch, git commit and (especially) git status. The traditional ones are, respectively: git co, git br, git ci and git st.

To do it, type these commands into your console:

$ git config --global alias.co checkout
$ git config --global alias.br branch
$ git config --global alias.ci commit
$ git config --global alias.st status


These commands change the global git config files, so you just have to run them once and you can forget about it (I mean, just remember the aliases).

Of course, you can define them differently, or add aliases for other git commands.

These commands change the .gitconfig file, which you can see by typing cat ~/.gitconfig

There should be something like this in the end:

[alias]
    co = checkout
    br = branch
    ci = commit
    st = status

Of course, you can simply edit this file to change or add new aliases, as you like.

Git language suddenly changed?

For some reason, it happened to me once that git (after some update, I think) on my MacOS machine started to show messages in my system language (which is Polish). I found it quite confusing, and possibly frustrating (in case of, for instance, need of googling some message - most of the world uses English, after all).

The solution is:

1. Check your locale (by typing LOCALE [ENTER] in shell):

~ LOCALE
LANG="pl_PL.UTF-8"
LC_COLLATE="pl_PL.UTF-8"
LC_CTYPE="pl_PL.UTF-8"
LC_MESSAGES="pl_PL.UTF-8"
LC_MONETARY="pl_PL.UTF-8"
LC_NUMERIC="pl_PL.UTF-8"
LC_TIME="pl_PL.UTF-8"
LC_ALL=

It seems my locale is pl_PL.

2. Add this line (of course change pl_PL to the value returned by your 'LOCALE' command):

export LANG=${LANG/pl_PL/en_US}

to the file ~/.zshrc (or .bashrc, or any other shell configuration file - zsh is default on MacOS).

Git tags listed from the newest, not the oldest.

The git tag command shows all the tags starting with the oldest ones, and if you are interested in the newer ones (which is typical, I suppose), you'll have to change the git config a bit, like this:

git config --global tag.sort -version:refname

No comments:

Post a Comment

Python crash course part 10: inheritance and polymorphism

In the last part we've shown how to create and use a class in Python. Today we're going to talk about inheritance: wchich means cre...