DEV Community

Cover image for Which git commands do you struggle with?
Ben Halpern
Ben Halpern

Posted on

Which git commands do you struggle with?

Which git commands and concepts do you have a hard time wrapping your head around and using regularly?

And with the commands you struggle with: Do you use them despite your difficulties or do you generally avoid them?

Source of the cover image. ๐Ÿ˜„

Oldest comments (46)

Collapse
 
cerchie profile image
Lucia Cerchie

I struggled with git-cherry-pick so I wrote a tutorial on it github.com/Cerchie/git-cherry-pick...

Collapse
 
ben profile image
Ben Halpern

Nice!

Collapse
 
cetholl_ profile image
Arif RH ๐ŸŽฎ

Nice sir. Thanks!

Collapse
 
brense profile image
Rense Bakker

I struggle with the existence of git cherry-pick :p

Collapse
 
murtuzaalisurti profile image
Murtuzaali Surti

The commands which I don't use often!

Collapse
 
omrubiks profile image
Om Bhamare

Lol

Collapse
 
alohci profile image
Nicholas Stimpson

It's not so much the individual commands as the entire philosophy. And the multiple commands that do the same thing. Or nearly the same thing. Or almost the same command that does something entirely different. So you're left feeling like "You're in a room with multiple exits, all the same".

Collapse
 
ben profile image
Ben Halpern

Have you considered using a tool or abstraction that helps? Just curious.

Collapse
 
alohci profile image
Nicholas Stimpson

I use TortoiseGit mostly. And eGit in Eclipse. And I used to use SourceTree. They all help a bit. But when things go screwy, I inevitably end up back at the command line.

Collapse
 
mfurmaniuk profile image
Michael

At least when you enter a wrong command you don't get eaten by a Grue

Collapse
 
tarwatuddin profile image
Tarwat Uddin

Since I code pretty much every project on my own, I regularly use the git rebase command which is a very powerful git command since it gives you the flexibility to modify local commits. Although hard to learn initially, it does get easier to use over time.

However, I wouldn't recommend to use such git commands in a group project setting as that could likely lead to "loose ends" in the git repo history (i.e. branch conflict issues) which can be a massive pain to deal with if you ask me.

Collapse
 
dumboprogrammer profile image
Tawhid • Edited

well it was,
git stash, which makes a temporary, local save of your code
& git bisect, a function that allows you to hunt out bad commits
but now I don't :D

Collapse
 
akshay9677 profile image
Akshay Kannan

Had a hard time wrapping my head around git rebase after learning git merge.

Collapse
 
diballesteros profile image
Diego (Relatable Code)

git rebase. On a larger level it can be quite annoying how different projects handle the way they want to handle git history only for it to be rarely referenced.

Collapse
 
alaindet profile image
Alain D'Ettorre

Rebasing: concept is clear, I can do a dead simple rebase, but rebasing in general is a struggle, so much that I almost always end up merging. My bad, I know.

Collapse
 
isaacdlyman profile image
Isaac Lyman

I support you, it's okay to merge. (I also don't really understand rebase)

Collapse
 
csgeek profile image
csgeek

rebase just pulls in the changes from a branch and keeps your changes on top. if you do a -i with rebase it lets you squash, reorder commits and a bunch of other things. It's very powerful IMO.

Thread Thread
 
isaacdlyman profile image
Isaac Lyman

So is it the equivalent of making a fresh branch off of the other branch, then cherry-picking all your commits back onto it? E.g.:

git checkout working-branch
git commit -m "My commit"
git rebase main
Enter fullscreen mode Exit fullscreen mode

==

git checkout working-branch
git commit -m "My commit"
git checkout main
git checkout -b new-working-branch
git cherry-pick {commit hash of "My commit"}
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
csgeek profile image
csgeek

Sure, but if you have 15 commits on your branch you'd have to cherry-pick all 15s. rebase is much easier to use, but it is equivalent if you want to use that.

It has other features (squash, reorder, etc) which are really handy that I mentioned earlier though for the standard behavior that is equivalent.

Collapse
 
jankapunkt profile image
Jan Kรผster

Rebase is so underrated but also so hard to grasp, which is why also often use merge or squash merges.

Collapse
 
c24w profile image
Chris Watson • Edited

I can handle interactive rebasing, but it does sometimes get you in a muddle. The thing is, you have to solve all the same conflicts as a merge, just not all-at-once and it keeps the history cleaner.

Collapse
 
thetwentyfive profile image
Anthony AHMED

It's more about the concept of conflicts instead a specific command.

Collapse
 
reactifystudio profile image
Reactify

Git stash ๐Ÿคฃ๐Ÿคฃ

Collapse
 
raj5036 profile image
Raj Karmakar

Git Stash is my best friend๐Ÿ˜†๐Ÿ˜†

Collapse
 
matthewsalerno profile image
matthew-salerno • Edited

revert has screwed me over a couple times. I think I get it now but it took a couple painful lessons to learn that it was not "revert back to this commit" but was actually "revert this commit and keep future commits." I ended up deleting my working commits and keeping my broken ones ๐Ÿ˜‚๐Ÿฅฒ๐Ÿ˜ญ

Collapse
 
sandeshsapkota profile image
sandeshsapkota

do we have this command in git ! really ?

Collapse
 
matthewsalerno profile image
matthew-salerno

Yup the man page even tells me not to do exactly what I did. Although it's not as bad as I made it sound as it doesn't actually remove the commit, it just makes a new one that makes it as if the commit never happened.

Collapse
 
sagefright profile image
sagefright

Agreed, I recently went on a rant about revert and got it all out of my system.
twitter.com/AndyHails/status/15103...

Collapse
 
supportic profile image
Supportic

git reflog

Collapse
 
roneo profile image
Roneo.org

git commit --fixup

Collapse
 
sagefright profile image
sagefright

WTF?1 Just read about this as a result of your comment. What is the point?!

Collapse
 
wormholecowboy profile image
Wormhole Cowboy

Kept forgetting to pull after adding a readme on Github. Then I wouldn't be able to push because of conflicts, so I had to learn how to use rebase.

Collapse
 
jwp profile image
John Peters

Visual Studio Code has a plug-in named GitLens. It is so good that I don't issue git commands any longer.

It includes rebasing,
auto resetting to any commit, changing the head pointer, full Visual commit history with code drill down ability to see modifications. Not to mention syncing, pushes and pulls, commits and branching.

Collapse
 
mondash profile image
Matthew Ondash

Oh for sure! Interactive rebase with GitLens is the bees knees! And managing branches and stashes has never been easier. Pair it with the Git Graph extension and it's a whole new world :D

Collapse
 
jwp profile image
John Peters

It's helped me out of terrible messes I did to my local and remote repos many times.