DEV Community

Cover image for 10+ things I always setup in git when I prepare a new environment

10+ things I always setup in git when I prepare a new environment

Shinji NAKAMATSU on July 29, 2022

When you buy a car or a bicycle, you first adjust the seat position and saddle height to suit your body size. It is the same with git configuration...
Collapse
 
tdwright profile image
Tom Wright

Great tips. Feels like this could be the start of a script. In fact, I can imagine an open source CLI tool for setting up Git just right on new environments, perhaps using a user-specific config file stored online...

Collapse
 
anasrin profile image
anasrin

The essential thing for me was add gpg sign and signing key

Collapse
 
francoislp profile image
François

Hey :) Great post, thanks for sharing!

How would you deal with 2 git emails on the same laptop?
one for github (perso) and one for work (pro)

The best would be to default to the email perso (and the associated GPG key), and when working from ~/Projects, always use the work email
Not sure if it is feasible ^^

Collapse
 
snaka profile image
Shinji NAKAMATSU

Perhaps you can.
I wrote an article about it, please check it out.

dev.to/snaka/use-a-different-git-c...

Collapse
 
tallesl profile image
Talles L

Nice tips!

However I was surprised to see "Do not fast-forward when merging" with the reason of making it "difficult to follow the history".

My personal experience is the exact opposite, having multiple automatic "Merge branch..." commits makes the commit history incredibly polluted.

Collapse
 
snaka profile image
Shinji NAKAMATSU

I understand your surprise, as I have seen several different organizations managing branches with different policies.

There isn't enough in this comment section to discuss that, so I will post a separate entry after I get more thoughts on it.

Collapse
 
suckup_de profile image
Lars Moelleken

To setup my environment for Linux or Windows I usually use my dotfiles : github.com/voku/dotfiles/blob/mast...

Collapse
 
snaka profile image
Shinji NAKAMATSU • Edited

Thanks for the link to your dotfiles! It is very helpful. 👍

Collapse
 
suckup_de profile image
Lars Moelleken

Good if you find something useful there. 😊

Collapse
 
joolsmcfly profile image
Julien Dephix

Do you always use cli commands or do you sometimes commit/push/pull/delete branches from your IDE?

Collapse
 
snaka profile image
Shinji NAKAMATSU • Edited

I use tig and git CLI depends on the situation.

github.com/jonas/tig

I often use tig to see logs and diffs, or commands with a specific commit ID, such as git cherry-pick <commit-id> or git rebase -i <commit-id>.

On the other hand, I use the git CLI for risky commands such as git reset, and for tasks that are faster with shell completion such as git checkout <branch-name>.

Collapse
 
joolsmcfly profile image
Julien Dephix

I see. I’ll check tig later out of curiosity!

I prefer using my IDE for most commands (I make sure to know what’s going on behind the scenes though) as I find faster (Ctrl+K to open commit window, type message, Ctrl+Shift+K to commit and push).

Collapse
 
buddhadebchhetri profile image
Buddhadeb Chhetri

Thanks for the tips this is really helpful.

Collapse
 
dominik90 profile image
Dominik Bartsch

Great tips, thank you!

Collapse
 
ravavyr profile image
Ravavyr

Neat...I install github desktop and click buttons.

Good article, it has its uses if you must use command line :)

Collapse
 
snaka profile image
Shinji NAKAMATSU

Your dotfile is also helpful. Thanks for sharing ✨

Collapse
 
wjplatformer profile image
Wj • Edited

git --checkout -b 'this post' 🔖✅

Collapse
 
officialismailshah profile image
ismail shah

Great tips will gonna use in my next project.....

Collapse
 
peterwitham profile image
Peter Witham

Some great suggestions in this list that I never thought about before, especially the global ignore outside of a project.
Thanks for sharing.

Collapse
 
devsimc profile image
Simc Dev

You also need to take care about this mistakes.
cmsinstallation.blogspot.com/2021/...

Collapse
 
snaka profile image
Shinji NAKAMATSU

Thanks for the link to a helpful article 👍

Collapse
 
piyushnags profile image
Piyush

I read that git push isn't supported fromthe CLI due to security reasons. Is there a nice way to get around that (other than using Github Desktop)?

Collapse
 
nstvnsn profile image
Nathan Stevenson • Edited

I use git push from the CLI all the time. I think you may have read that where it talks about setting up ssh keys.

If you are using your IDE or the Desktop UI for git, you are likely signed in to your github account through them. No issues.

With CLI, you need to set up SSH for authenticating your pushes from the CLI:

docs.github.com/en/authentication/...

Collapse
 
piyushnags profile image
Piyush

Thank you, after switching to SSH it works just fine

Thread Thread
 
nstvnsn profile image
Nathan Stevenson

No problem! Glad you got it working.

Collapse
 
snaka profile image
Shinji NAKAMATSU • Edited

Sorry, I didn't catch what you meant by "git push isn't supported formthe CLI due to security reasons".
Could you please add what you mean by that?

Collapse
 
piyushnags profile image
Piyush • Edited

Yep my bad, I wasn't clear enough and I also realized I didn't read the documentation properly :(. I was trying to push some changes to my repo through the terminal. However, I was trying to push via HTTPS. According to GitHub, it no longer supports authenticating through HTTPS for the CLI (I had mistakenly assumed that pushing from CLI in all cases was no longer supported, which is pretty silly in hindsight). After I switched to SSH as suggested by Nathan (from the below response), it works just fine. Side note: great tips now that I can use CLI again!

Edit: If you're curious, you get a 'fatal authentication' error if you try to push via HTTPS. Apparently, they stopped this since August 2021.

Thread Thread
 
snaka profile image
Shinji NAKAMATSU

Ah, it was clear to me what you said.
I'm pleased that your problem was resolved as a result.

Thread Thread
 
jasperhorn profile image
JasperHorn • Edited

git push, from the command line, to GitHub, over https does work. It's just that you don't use your password to login. Instead, you use a token, which you first need to generate in your settings somewhere.

Thread Thread
 
snaka profile image
Shinji NAKAMATSU • Edited

Thank you for the additional information.
As you mentioned, it is possible to push via HTTPS with the git command by using a Personal access token (PAT).

Here is a link to the GitHub documentation for reference.

docs.github.com/en/authentication/...