For people new to Git, it can be confusing and intimidating. If that's you, here are six Git commands for your toolbox. With these, you can become ...
For further actions, you may consider blocking this person and/or reporting abuse
Don't forget about:
:)and
git pull origin master
git reset --hard
git stash
git stash pop
merging into master should be done via pull request imho
I appreciate the joke :)
You can appreciate the joke as an experienced developer in git, that knows the implications of using it, but we need to be careful when trying to make jokes for the ones that don't get the context of it, specially when the article is targeting beginners.
I thought it was pretty funny myself, but you also make a good point. Thank you for bringing it up!
I agree, hence my acknowledgement of the joke for what it is.
This is a very bad advice, and should be never used, not even in solo projects, because you get into a bad habit that can have pretty nasty consequences in a professional environment, like Jenkin developers accidentally do "git push --force" to over 150 repos on github.
I don't have the link anymore, but I read a story once of a company that took months to recover from a
git push --force
to their master branch.To be on the safe side ALWAYS configure your Github, Gitlab or whatever you use to not accept push to
master
.Cause you are on forked repo
Trololololol...
You forgot the most important of all
git checkout -
:It's just like our old Linux friend
cd -
;)Ok, the above one is more a tip, but a very important command to know about for beginners is
git stash --help
andgit show --help
With
git stash
we can save our changes that are not commited yet, and if we include-u
we will save also the files not tracked. It's useful to clear the workspace or to move code not committed yet to another branch or just to later reuse on the same branch, just by doinggit stash apply
.With
git show
we can see thegit diff
for the last commit, and withgit show <commit-hash>
orgit show HEAD~3
we see thegit diff
for that specific point in history.When things go terrible wrong, like you delete accidentally a branch, you can use
git reflog --help
to see your history of changes and get back to a good state.Very useful tips.Thanks a lot, especially for the idea to use git stash apply
Agreed! These are awesome tips. Thank you!
git 2.23 introduced
git switch
for switching branches.More info is available here
You mention you could shorten
git checkout
togit co
, but you never explain how to configure that alias.Good catch! Thank you -- it completely slipped my mind, which is unfortunate. I just edited the post with instructions on how to do it.
Extend it to 10 and add git rebase, cherry-pick, push, fetch
I feel like git clean would be a good one toio
Thanks to everyone in this thread for the responses! These are some really great tips.