You don’t need the git CLI
Tags: programming, tutorial, productivity, watercooler
Published: 2022-10-30 16:32:18

Please wait a little before you start… `bashing` me.

## The CLI

You should totally learn the CLI and it’s still important to know what to do when, for some reason, the GUI you’re using have some problem. Also, that was, clearly clickbait…right?

## Living outside the CLI

I use VSCode with [Git Lens](https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens) to the point I have no idea how much of what I’ll be saying here is just the VSCode alone and what is done through Git Lens. But if you’re using VSCode, then you only have to gain to install Git Lens, if you haven't yet.

Another extension worth mentioning is the [Conventional Commits](https://marketplace.visualstudio.com/items?itemName=vivaxy.vscode-conventional-commits), which lets you compose beautiful commit messages and make you remember each part of the commit according to the [Conventional Commits](https://www.conventionalcommits.org/) specification. 

## The tool you’ll use

If you’ve skipped, if I say something and you don’t find it in your VSCode, then maybe it’s the lack of having Git Lens installed.

You have a whole tab dedicated to Git. 

![source control icon](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jbzn7nj17m3jqdgajozw.png)

It shows tracked and untracked files, it shows all repositories if you have multiple in your workspace, and it also shows branches, repositories, stashes… basically everything you need and more.

## For using branches

Some people end up missing this, but on the bottom corner:


![bottom left corner of vscode with branch and sync buttons](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aardx9qxijnrak3yd3qt.png)

You can easily sync changes (it already shows you if there’s something incoming or outgoing).

If you don’t have any changes it also makes clear you have changes to push or to pull:


![1 sync changes to push](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vaszu4ty8u96po7t7u0s.png)

![1 sync changes to pull](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gblngdi2ylepgxj09v04.png)


So, no more excuses for “I forgot to push”.

And by clicking the button with the branch name you can easily change branches or create new ones.

## For committing

If you've never checked out, you would probably see something like this when you have some changes:


![source control section with changes in list view](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9qlzx2y41hn52j29m8zk.png)

The first thing I recommend is to switch to tree view (it’s the bunch of lines icon above the message input). You should be seeing something like this:

![source control section with changes in tree view](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v84e4db84iecezk32msg.png)

The files with `M` mean “modified” files. 

The files with `U` mean “untracked” files (new files).

The files with `D` mean “deleted” files.

You can also check the colors of those letters.

They show you new (green), modified (blue), and deleted (red) files.

And (if you have any kind of lint and other extensions that find it) they also show you if they have warnings (orange) or errors (red).

### Working with the changes

When clicking or while hovering you’ll see:

![buttons on hover/click](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/650lkyhwwg0hys1mltf4.png)

You can jump to the file, discard and stage the changes.

When clicking or hovering the “Changes” or “Staged Changes” line:


![changes with buttons](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vq20hw4yu3xcyoijcimo.png)

![staged changes with buttons](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/upf7c5b5dz8wpbcovy9x.png)

You can stage/unstage all of the files, discard all, or even stash them.

Also, when you click it, it opens the changes:

![changes tab open](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mwkclax9nb4lfab6bnei.png)

(You can use inline changes if you prefer it in the “…” (three dots) button)

### The one feature that makes it worth it

So far, it shows all in a neat way, but all of that you can easily do in the CLI, and some do prefer it that way, but this is the thing that will make you think twice and I dare to say: this actually changes the way to code!

Let’s say you have this:

![file with lines with errors and one line with console.log](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ppzs2g91ojvqg2s4p8vf.png)

Lot’s errors, but you have one line working that will work by itself… do you commit the whole file with all the breaking errors, or… what do you do?

Well… you can as easily as two clicks… stage only one line!

Right-click the line:

![right click opens range commit section](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3czfzy8kltc4cq3m8n3u.png)

Then left click on “stage selected ranges” (that could be multiple lines selected):

![only the line selected is staged](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dgn5sb3i8orsudc9y3ac.png)

Now commit only the line that’s working by itself without even having to touch any of the work you don’t want to touch right now.

(Yes, I know it’s possible to do that with CLI, but nowhere near as easy as that!)

**Want more?**

This could be a bug that is actually a feature… but you don’t even need to have the changes you’re staging saved! Yes. You can stage unsaved changes! **🤯**


![staging unsaved line](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yguu0grbcmrp42v00njj.png)

![after discarding changes](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/90lrl3r8rk6krgsdz28t.png)

(As you stage changes, the left panel shows what’s staged. When you discard your changes, it picks that difference.)

I’ve discovered that because I usually force filters of tests “fdescribe/fit” and I had committed those “f”s while still using them. So I just changed the line and staged, and only then I saw I hadn’t even saved it.

So if you need to make little changes to make sure that you can open a commit and it works, you can do them without even saving. Change, stage, undo.

## Managing stuff and other things

There are a lot of other things you can do, especially regarding syncing, changing, deleting, and renaming branches, and stashes.

Don’t forget to check the command pallet to see other cool stuff you can do.

My preferred one is to cherry-pick (use the GitLens one for this one).

You can also, on each file, navigate the changes commit by commit.

---

I probably forgot to mention a lot here… so ask away! And leave yours too!

---

Cover Photo by [Praveen Thirumurugan](https://unsplash.com/@praveentcom?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/s/photos/git?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)

For anyone interested:

- Theme: Dracula ([Dracula Official](https://marketplace.visualstudio.com/items?itemName=dracula-theme.theme-dracula))
- Icons: [vscode-icons](https://marketplace.visualstudio.com/items?itemName=vscode-icons-team.vscode-icons)
- Font: VSCode default