Git - basic configuration


Good software developer should be lazy! But in a good way :). If you want to be good or the best start from optimizing your work. You can start with this tutorial to find out how to type less when using Git.

Git basic configuration to start with

Like usually, I assume you are correctly prepared for this tutorial. If no this is the best time to do it :). Below you will find the list of things you need before you can start with this short tutorial:

  1. Installed Git version control system;
  2. Text editor - I will work with Vim;

Ok. I hope this very long list will not force you to leave reading ;) - so let's start with actual "meat".

Assumptions

  1. We will adjust git global configuration file - you can always change it and even override it in a local repository.
  2. I will use bogus data like names, emails, etc. - please change them to your real ones where needed.

Configure who you are

Each time you produce a commit - it must be signed (I'm not talking about digital signature - but you should also consider this) to show who is an author.

# replace "Your Name" with your real name or nick - whatever you want to be visible in commit as an author
git config --global user.name "Your Name"

# replace "your@public.email" with the email you want to be displayed as authors' email
git config --global user.email "your@public.email"

You can verify if everything is ok - please check typos - everybody makes them sometimes even in their names :)

git config --list --global

Stop git from cleaning your mess

Git can change line endings of your source files from \n to \rn and vice versa. But do not use this! You are a software developer and you can set up your code editor to use line endings expected in your project. You can even work on multiple projects with different line endings. Again, you are a software developer, you can and you will set up your code editor correctly!

git config --global core.autocrlf false

You should also define the global gitignore file where you will put wildcard masks of files you must not include in your repository - like:

  • code editor configs,
  • auth config files,
  • etc.;
# I keep such file in my home directory - but you can store it wherever suits you
touch ~/.gitignore

# git must know where this file is located
git config --global core.excludesfile '~/.gitignore'

# I'm using Visual Studio Code so I will exclude its config files globally
echo ".vscode" >> ~/.gitignore
echo "*.code-workspace" >> ~/.gitignore

Type less

Most of Gits' commands are too long for me - I prefer something shorter - but not too short so I can still remember what this shortcut is for.

# `git checkout` -> `git co`
git config --global alias.co checkout

# `git status` -> `git st`
git config --global alias.st status

# `git commit` -> `git ci`
git config --global alias.ci commit

# `git diff --staged` -> `git staged`
git config --global alias.staged 'diff --staged'

# `git reset HEAD --` -> `git unstage`
git config --global alias.unstage 'reset HEAD --'

# `git checkout @{-1}` -> `git last`
git config --global alias.last 'checkout @{-1}'

# `git pull --ff` -> `git puff`
git config --global alias.puff 'pull --ff'

# `git push origin <current-branch-name>` -> `git poc`
git config --global alias.poc '!git push origin $(git rev-parse --abbrev-ref HEAD)'

I hope the above shortcuts will help you with being more productive. I use them for several years now, and I don't know how to live without them.

Stay versioned and git ci -m "Good Bye"!

Not enough?


Would you like me to build and conduct training tailored to your needs? I'm waiting for your call or message.

address icon

WeBee.Online Adam Wojciechowski
ul. Władysława Łokietka 5/2
70-256 Szczecin, Poland