We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 9
e
7 Git
Techniques and Shortcuts
a quick guide by @meakcodesTechnique 1:
Git Commit
I assume that you already know how to use:
git-demo 5 git add .
git-demo $ git commit -m “hi mom"
[master d6b7949] hi mom
1 file changed, 1 insertion(+)
git-demo
But theres actually a better way how to do it:
git-demo $ git commit -am “that was easy!"
Sata s olen 4-10 eT TTS
1 file changed, 1 insertion(+)
git-demo
Just get rid of the “git add . “ and “git push”
and just type * git commit -am ““ *
note: new files will be not tracked.Technique 2:
Git stash
Let's say you have implemented some code,
but you don't want to share it yet. You just
want to save it without publishing it for now.
Thats where git stash comes in:
git-demo § git stash save coolstuf fl
the code know will be hidden and not visible, its like it never existed.
example: it will be saved under the name “coolstuff’
Then when you're ready to use it again:
use git stash list to view a list of all stashes
git-demo $ git stash list
stash@{@}: On master: coolstuff
git-demo
Then choose your respective stash:
choose the stash with the current index
git-demo $ git stash apply ITechnique 3:
Git log
Imagine you want to view the latest commits from
the past. You might currently be using ‘git log' for
this.
fireship t log
But that's actually not a great idea because it's
hard to follow due to all the information being so
unstructured: it will look like this!
commit a8db8aecd3fc5912Fb611923d6Feb397Fa3a6alf (orig
in/master, origin/HEAD, )}
Author: Jeff Delaney
Date: Fri Sep 3 15:26:31 2021 -9700
add dispatch to gh actions
Just use the VsCode Extension GitLens:
there so many features, definitely give it a try!Technique 4:
Git revert
Consider a scenario where you need to switch to a
different commit because you made a mistake and want
to revert to a specific section of your commit history:
Use git log to show the last commits and copy that
commit id: ~
rr
Date: Wed Oct 13
eer oad
Now, enter the command ‘git revert’ followed by
the copied ID from the last commit:
Using ‘git revert' does not delete your previous commit.
Instead, it generates a new commit that effectively
undoes the changes made in the specified commit. It
allows you to selectively undo a particular commit
without affecting the rest of your commit history.Technique 5:
Git log -S “”
Picture a situation where you recall having specific words
in your code, but now you can't locate them. You wish to
investigate where those words are currently within your
codebase.
For example our README.md file looks like this:
{} package,json
README.md
Cae g
eR bs
Let's find out where 'Text 2' was changed and see
who made those modifications.
Just use git log -S “” and in our example with “Text 2”
you will then all commits related to “Text 2”
useful-custom-react-hooks
$ git log -S "Text 2"Technique 6:
Git branch --prune
Imagine you have an old branch that you no longer use,
but it still exists locally. Learn how to completely delete it:
To view the current and last branches type: git branch -vw
Pra erates s.)
sta ra
As you can see, we have one old branch and one
main branch. Now, we want to delete that old one!
Use git remote update --prune , it will delete the reference to
your remote repository if the branch no longer exists.
Pree Tt
Pra e eful-custom-reacTechnique 7:
Git rebase
Imagine you working in a Team and you need to
implement a feature and want to merge it later:
Create another branch, let's name it 'feature1' for example, and then check
out that branch:
i Switched to branch 'feature1'
pea lalla ma hs a ee
Chee tae hha ae
cl
Now let’s commit something to that branch:
note: that is not the master branch!
Tee Berd Bre)
eT) ear rear
Pet oC Pets Pare TS git commit
Creer)
Lets go back to the Master Branch:
5 Sod LL
Pp R lel ce hatoa t —
besos]
*
Now, simply use rebase to integrate your features into the
master branch.
Simply use ‘git rebase' with your current branch, let's say
‘feature 1,' and indicate the branch where you want to merge it.
In our example it’s the master branch.
git rebase featurel master
your feature branch to masterBefore you go!
Please leave a positive review on Gumroad!
good luck & keep learning!