What we need to configure Git!
- Tutorial
Darova, Habr! (I didn’t come up with anything more original)
I doubt that this note draws to a full post, but I still leave it here. What will it be about?
We all heard about Git. We all know that he is good. But only a few try to do something with him, somehow tweak it. I must say right away that there will be nothing paranormal, just a little work with the .gitconfig file . Yes, yes, it is with that file that is so anxiously gathering dust in your home directory.
So, I'm already a little tired of writing this essentially meaningless introductory text, so let's already start to do something.
What is .gitconfig and why is it needed?
Git comes with a great .gitconfig file as standard. Its purpose is obvious from the name. Strictly speaking, this is a user config. It allows you to configure aliases, add-ons, etc.
I do not know how on other systems, but on Linux it lies in ~. If it is not there - feel free to create!
I do not know how on other systems, but on Linux it lies in ~. If it is not there - feel free to create!
We open .gitconfig in the text editor convenient for you (for me it is nano).
Output backlight
Reading Git’s conclusion “dry” is quite difficult. I saw a lot of people who endured it. After one wonderful command, they felt better. To enable color output, add lines to .gitconfig:
[color]
ui = true
We record ourselves
Why is this needed? If you run git log for some kind of repository, you will see that for each commit, the author is characterized through Name and Email. To find us correctly, it is time to ask all this correctly. Attention! Changing this information during development is highly undesirable. She can break the story (multiple authors)! It is advisable to select a name and a specific Email once.
[user]
name = Anonymous Doody
email = anonymous.doody@anonymous.com
Commits template
I don’t know how other Habrovsk people work, but basically my commits go to KDE Edu projects. They clearly dictate the rules of the form and type of the commit, since it is parsed by different bots, etc. In order not to let God make mistakes or do something wrong, there are patterns. Such a template is very simple to make (or you can take it somewhere). To make it appear during git commit, you need to add this:
[commit]
template = ~/.commit-template
In this case, ~ / .commit-template of course can be any file on your file system.
Credential helper
It happens that you need to perform several operations with a remote repository at a time. Each time you enter a name and password, name and password, name and ... Annoying, no? It bothers me. Starting with version 1.7.10, Git supports Credential Helper.
[credential]
helper = cache --timeout=<время>
Set the right time (I have 3600 - one hour) and rejoice!
Alias for frequent teams
I very often use the checkout and branch commands , for example. Writing three or four times the same thing is boring. Let's replace them with a more concise version: cd and dir , for example.
[alias]
cd = checkout
dir = branch
mersq = merge --squash
free = branch -D
Now let's see what we did:
No modifications | With modifications |
---|---|
|
|
Prefixes for remote
There is one trick that is often used by developers. These are the prefixes for remote. They allow you to reduce the length of the address to the remote repository. You can set these for read-only and push. What for? This is logical for open-source projects. To reduce server load and speed, it is better to pull from anongit (read-only) without using SSH. What do I have for KDE?
[url "http://anongit.kde.org/"]
insteadOf = kde:
[url "git@git.kde.org:"]
pushInsteadOf = kde:
Let's get it right. Here we set up two URLs for pull and push. Set the kde prefix. What does this give us? Let's look at an example (the article does not specify the gh prefix - for GitHub):
No modifications | With modifications |
---|---|
|
|
It got better, right?
Conclusion
The article omitted all my "exotic" aliases and ext. prefixes for different services. I can safely say that after Git tweeted, it became more pleasant to work. All the acquaintances who tried this agreed with me.
PS If I am doing something wrong or I'm already completely miserable, please write to me on the PM and let me know / advise (if it’s not difficult for you, of course).
UPD : More interesting and fresh can be found here .
Happy coding!
Only registered users can participate in the survey. Please come in.
Was this article helpful to you?
- 21.5% A lot of new things learned 419
- 52.4% A couple of moments pleased 1021
- 25.9% Aftar, you are captain 505