In this post, we're going discuss some very useful tricks on Git which literally can save your ass if you screwed up things on Git. Now, without an...
For further actions, you may consider blocking this person and/or reporting abuse
This is such a time saver...
Switching back and forth between two branches:
That's going to be very useful for me. Thanks for sharing this one.
-
in general is wonderful. I sometimes forget it exists forgit
,cd
, and others. It makes jumping around directories/branches so much faster.Hey, thanks for sharing.
Couple of notes:
is a bit confusing i'd suggest changing to:
Rename branch locally
Delete the old remote branch
Push the new branch, set local branch to track the new remote
Thanks for describing in detailed way 😁
I always forgot the command to push a delete branch on remote.
For the latter, I like to do:
:D
be frugal
git add .
@maestromac would freak out if he saw me doing this 😝
It hurts me even when I do it.
If you have untracked files
git add .
will add them, whereasgit add -a
will not.I like to use from time to time, to see where am I fetching/pushing.
Made few times a error where I would copy some dir to another dir and .git would get overwritten :)
I also like to use this to see where all my branches are tracking from:
It tells me which branches currently exist on my machine and which remotes and branches they are tracking. This is useful if you work with a team and you add their remotes to pull their branches down. It can get confusing to keep track of which branches are pointing where so you know where code is going to land when you run git push or where the changes are coming from if you do a git pull.
The branch with the asterisk is the one I currently have checked out.
Thanks for sharing.
Wow... git reflog is the best part of this article. Thanks!
👍🏻
What is very important, that these commands rewrite history. And when you rewrite history, you actually create new commits and the old ones stay intact. So if you've pushed already, then after using any of these commands you won't be able to push without --force. And once something is shared it cannot be unshared. Be careful and know what these commands lead to.
I wouldn't call these hacks or tricks, though. Most of these is a regular workflow stuff.
But "hacks" sells more than "commands".
Never knew that one! Thanks!
👍🏻
git commit --amend
will add anything in the staging area (or index; the thing files get to when usinggit add
), and let you change the commit message. If you only want to change the commit message leaving the index alone, you can usegit commit --amend --only
.When you want to remove a file from the latest commit, after using
git reset --soft
and co. you can usegit commit -C ORIG_HEAD
so you don't have to enter the same commit message.👍🏻
An easier way to remove a file that has been added to the last commit by mistake:
This doesn't delete the file, though. Dropping '--cached' would delete it.
Great 👍🏻
git bisect
but that needs a whole article in itself. If you haven't heard of it, it's a way of quickly pinpointing at which point in history a commit was made, eg. you just noticed a bug, and want to find which code change caused it.Wow, thanks for sharing 😁
Thanks. Very useful.
Glad you liked it 😁
Did you use?
I use aliases for that :
git lga
show the whole tree,git lg
show just your branch. Can't work without it, I need to know the state of the commit tree in shell very often.I don't use it in a daily basis. But it's very useful.
git commit --amend
can be use to add new modifications to the previous commit.You can edit a file and mark it to commit
and then
to insert the modifications in the previous commit.
There is a short hand for renaming the current branch which isn't mentioned:
git branch -m new_branch
Thanks for sharing 😁
For the rest: We have git-tips 🔥
Very useful list man. Thanks for sharing 😁
Good share @i_ankurbiswas
Glad you liked it 😁
Renaming branches >>>
Thanks for the tips - def will save me some time in the future!!
👍🏻
I knew git amend but git reflog that's a cool one ... and git checkout - is a really handy one
👍🏻
Very useful
Glad you liked it 😁
Extremely useful post, thanks Ankur 👍
Glad you liked it 😁
This is a great list. I have used amend for the last commit more times than I might be prepared to admit :)
Glad you liked it 😁
Reflog saved me recently. Such a good one
👍🏻
"Hacks" is pretty inaccurate, more like "commands"
You got me 😄
Sure, DM me on Twitter
The non-intuitive nature of Git seems to be an opportunity for writing a full-featured GUI on top of the arcane command line wizardry required to do most anything other than a commit.