DEV Community

Cover image for 5 git tips for beginners

5 git tips for beginners

Olivier on January 26, 2022

Practical commands for efficiency and a clean tree 1. Shortcuts (aka Alias) You will find tons of alias ideas out there, the ones I fou...
Collapse
 
cyberjack profile image
CyberJack

As a beginner, isn't it better to learn the real commands instead of learning the aliases?

Your aliases are only available on machines with your git configuration. If you depend on aliases, you'll run into problems if they're not available (if you need to work on another machine, for example).

Also, look at switch to manage branches. Checkout has multiple responsibilities, which isn't a good thing. Switch and restore were created to split these responsibilities into their own commands.

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️ • Edited

Good aliases make it easy to remember the long hand versions:

git config --global alias.dog 'log --decorate --oneline --graph'
Enter fullscreen mode Exit fullscreen mode

Checkout has multiple responsibilities, which isn't a good thing

Yep, that's really a problem with some git commands: they do too much and often unrelated things.

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

Unless you where born in the 1980s you likely hate vi or vim editor

Correction: unless you were born in the 1980s or have taste 😂

But seriously though, (neo)vi(m) is a great editor and too many people form their opinion of it based on memes and having been stuck in it half a dozen times because :q<enter> is honestly just too hard to remember.

Collapse
 
northbear profile image
northbear

It's how I distinguish first class citizens in Linux from guests. They may be advanced guests, but guests.
And I should say that there is nothing bad with being guests for me. I'm the similar guest in Windows systems and cannot say that I'm also a First-Class Citizen in MacOS (though I'm much stronger there than in Windows. I was grown up from FreeBSD that is in roots of MacOS). So, it's okey. Each to their own...

Collapse
 
northbear profile image
northbear

Good tips! I would skip the recommendation about dprod alias it's not for beginners and matched to a specific workflow. One more updates, I'd make about rebase. it's more comfortable to use a commit's short hash for rebasing. If the branch has more than 10 commits it's become tricky to count amount of commits...

Anyway, well done!

Collapse
 
thumbone profile image
Bernd Wechner • Edited

Born in the 1980s to love vi? Ha ha, I was born in the 1960s and was weened on vi.

Your point remains a good one, vi sorta sucks really. It's just that some of us were weened on it. And I can't stand nano.

I go one better IMHO. I tend to use Atom 😉. Of course that's a GUI editor but I manage all my servers from a desktop machine, mounting drives with sshfs and using ssh to get a CLI on them, in which context I use vi because it's familiar but appreciate nano is much easier for newcomers. But as I said, I don't do a lot of text terminal editing, I tend to mount with sshfs and edit in my DE.

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

I'm more of an ssh + tmux + neovim person myself, but sshfs go brrrrr

Collapse
 
thumbone profile image
Bernd Wechner

Each to their own. But what does "go brrrr" mean? sshfs rocks. I can mount userdirs and root dirs in a jiffy and navigate them with a system explorer, edit with GUI editors, check logs with klogg and more ...

Thread Thread
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

I hadn't even considered the idea of mounting local directories with different users; so far I've only really used it to open remote files on my office PC in GUI editors on the laptop I use when working from home.

Thread Thread
 
thumbone profile image
Bernd Wechner

Oh, I only use it for different users when I'm working on my servers. For security reasons, every server has a name, and a user name that is mnemonically linked to the server name. Root login is then disabled on the server, and that main server admin account is a sudoer. Thus I would often sshfs using that admin account less commonly as root for the whole filesystem (root login only permitted from the LAN with a sshkey not a password). To keep risks low with both my use and any possible mal-vectors I use the lower level of accounts when that's all I need and I make sure its in the right groups to read logs and such.

Collapse
 
elvisoric profile image
Elvis Oric

In my opinion, shortcuts (aka aliases) should be avoided by beginners.
At the beginning, pay attention to familiarize yourself with the original commands.

And use "a dog" association if you have hard time remembering:
git log --all --decorate --oneline --graph

Collapse
 
harleendev profile image
Harleen 🏳️‍🌈

What's wrong with vi? ;)

Collapse
 
roneo profile image
Roneo.org

I would recommend 'micro' instead of nano. It comes with human-friendly shortcuts like Ctrl+S and Ctrl+Q

Collapse
 
sebbdk profile image
Sebastian Vargr • Edited

First rule of git club, git gud'.

Collapse
 
ziker22 profile image
Zikitel22

Or you can use ZSH git plugin and you get all those aliases stanradized and for free
github.com/ohmyzsh/ohmyzsh/blob/ma...

Collapse
 
bobbyiliev profile image
Bobby Iliev

Great tips! Well done

For anyone interested in learning the basics of git here is a free eBook:

GitHub logo bobbyiliev / introduction-to-git-and-github-ebook

Free Introduction to Git and GitHub eBook

💡 Introduction to Git and GitHub

This is an open-source introduction to Git and GitHub guide that will help you learn the basics of version control and start using Git for your SysOps, DevOps, and Dev projects. No matter if you are a DevOps/SysOps engineer, developer, or just a Linux enthusiast, you can use Git to track your code changes and collaborate with other members of your team or open source maintainers.

The guide is suitable for anyone working as a developer, system administrator, or a DevOps engineer and wants to learn the basics of Git, GitHub and version control in general.

🚀 Download

To download a copy of the eBook use one of the following links:

📘 Chapters

Collapse
 
andrewbaisden profile image
Andrew Baisden

The more you use git the better you git 😁