DEV Community

Cover image for The Git Commands I Use Every Day

The Git Commands I Use Every Day

Wade Zimmerman on September 17, 2022

1. Get all latest changes without merging Stop pulling code that you think will break! Having fetch in your workflow allows you to grab ...
Collapse
 
webjose profile image
José Pablo Ramírez Vargas

Call me crazy, but I have never, EVER, had to type a single git command. I use Visual Studio Code with the Git Graph extension. It does everything for me without having to invest brain cells in learning a bunch of CLI commands.

Collapse
 
wadecodez profile image
Wade Zimmerman

It's worth it because then you can pretend to be a hacker!

Collapse
 
jessekphillips profile image
Jesse Phillips

The issue I have had is that people don't know how to use their UI. This is true with command line as well, but then we would at least be in the same environment.

If we used the same GUI then that would be the same. But I find every GUI to be dangerous. They try their best to help but always make it easy to throw out unsaved changes (git hates doing this).

I have not found a git GUI where I don't need to spend mental energy getting the GUI to do what I want.

Collapse
 
mroeling profile image
Mark Roeling

But I find every GUI to be dangerous.
I almost agree. I find most git GUI too dangerous. I use GitCola for basic things, I but almost always fall back to the good old cli.

Btw, new command learned! git switch -c new-branch
I normally run git stash ; git checkout -b new-branch ; git stash pop to achieve the same result.

Thread Thread
 
jessekphillips profile image
Jesse Phillips • Edited

But switch -c and checkout -b are the same. They both require stash if git needs to update a modified file.

Collapse
 
netch80 profile image
Valentin Nechayev

Does it allow interactive rebase? Rebase onto another branch? Bisecting?
Pushing of a specific revision (not head)?
(I mention only actions I have to do regularly)

Collapse
 
webjose profile image
José Pablo Ramírez Vargas

Rebase for sure but don't ask me. Install it and see for yourself. If it suits you then great.

Thread Thread
 
drsensor profile image
૮༼⚆︿⚆༽つ

lol

Collapse
 
madalinignisca profile image
Madalin Ignisca

So you depend on many others for minimal needed git things for CI/CD?

Collapse
 
webjose profile image
José Pablo Ramírez Vargas

I have my minions for CI/CD, yes. I focus on programming, and then I let them lift that part for me. :-)

Collapse
 
jakeroid profile image
Ivan Karabadzhak

I work inside IDE, but use console for git just for fun.

If I should make some complex merge, then I prefer to use some GUI to be sure everything is going OK.

Collapse
 
cess11 profile image
PNS11

So you're not the go-to guy when things break in unexpected ways in your workplace.

Collapse
 
webjose profile image
José Pablo Ramírez Vargas

Git-related? Usually not. But then again, under my eagle eye things don't break. :-)

Collapse
 
tahsin52225 profile image
Tahsin Ahmed

I use that too but being old school have it's own level of satisfaction :P Cheers

Collapse
 
goodevilgenius profile image
Dan Jones

I would encourage you to add that last function as a git alias, rather than a command in your .bashrc.

Something like:

git config --global alias.fc 'f(){git checkout "$(git branch --format="%(refname:short)" | grep $1)";}; f'
Enter fullscreen mode Exit fullscreen mode

Then, you call it with git fc dropdown. Sure, it's more characters to type, but it enforces mentally that it's a git command that you're running, and, if you ever switch shells, you don't have to move that over.

Collapse
 
spo0q profile image
spO0q 🐒

you can also type git push -u origin HEAD for the upstream.

Collapse
 
wadecodez profile image
Wade Zimmerman • Edited

Yeah definitely use the -u or --set-upstream flag if you use git pull in your workflow otherwise you'll have to type git pull origin <branch>.

I don't use pull though

Collapse
 
vdnsnkv profile image
Valentin D.

I'm sorry, maybe I'm missing something. But why do need to type git push production head if you can just do git push? It will push your current branch to it's remote.

Collapse
 
alvesjessica profile image
Jessica Alves

Nice article! I also like the
git add --all -p

Collapse
 
jaminologist profile image
Benjamin Bryant

Cool, article! I'll make use of this one:
git switch -c new-branch

Collapse
 
naucode profile image
Al - Naucode

Great article, keep the good work! Liked and followed! 🚀

Collapse
 
geesilu profile image
Luthira Geesilu

Thanks Wade!

Collapse
 
jakeroid profile image
Ivan Karabadzhak

Great article Wade, Thank you!

Collapse
 
wiseai profile image
Mahmoud Harmouch

Never heard of git switch; Good to know. I am now wondering about the difference between switch and checkout.

Thanks for sharing, BTW! Keep it up!

Collapse
 
netch80 profile image
Valentin Nechayev

"switch" and "restore" are relatively new offsprings from "checkout" (approx. 2 years old). It's not strange that many guides still omit them.

Collapse
 
jessekphillips profile image
Jesse Phillips

Switch is an improved interface from checkout. Have not needed checkout though: git switch --detach , is a bit longer.

For example previous branch: git switch -

Collapse
 
iizmotabar profile image
Motabar Javaid

Thanks Wade!

Collapse
 
vinceamstoutz profile image
Vincent Amstoutz

One of the most interesting cheat sheets I've seen on Dev.to and Medium if it's not the most interesting one, thanks for the tips! @wadecodez

Collapse
 
drsensor profile image
૮༼⚆︿⚆༽つ

I use: fzf.fish, gitui, lazygit, difftastic, delta, git-filter-repo, and git-branchless; for git-ing my stuff. Don't ask me why I don't use VSCode 😂

Collapse
 
lushs profile image
Troy Kirinhakone

Thanks! Now we need some noble person to make such an article on git submodules, especially in a monorepo such as Nx.

Collapse
 
mrcod3rir profile image
mrcod3r-ir

tnx