
No Comments Yet
Be the first to share your thoughts and start the conversation.
GSAP Course launch discount ends soon!🎉
Claim DiscountBe the first to share your thoughts and start the conversation.
How did you manage to remove the blur property and reach here?
Upgrading gives you access to quizzes so you can test your knowledge, track progress, and improve your skills.
By logging in, you'll unlock full access to this and other free tutorials on JSM Pro.
Why? Logging in lets us personalize your learning experience, track your progress, and keep you in the loop with new workshops, coding tips, and platform updates.
You'll also be the first to know about upcoming launches, events, and exclusive discounts.
No spam—just helpful content to level up your skills.
If that sounds fair, go ahead and log in to continue →
Enter your name and email to get instant access
In this lesson, we explore the fundamentals of using Git for tracking changes in a project. The instructor demonstrates how to create files, track them with Git, and understand the process of committing changes while highlighting the importance of keeping a record of project progress.
hello.js
is created and Git prompts to add it, but is canceled for manual explanation.hello.js
and readme.md
are created, showcasing basic logging in JavaScript.git status
is used to check the current state of the repository, revealing untracked files.git add readme.md
is utilized.git commit -m 'add readme.md file'
is used to save changes with a descriptive message.git add .
allows adding all changed files to Git tracking in one action.git log
, which provides commit IDs, authors, timestamps, and messages.git checkout
.git checkout
won’t delete logs or history, maintaining a safe exploration of past states.00:00:00 Let's add some files and track changes.
00:00:02Â I'll create a new file called hello.js.
00:00:06Â And you can see how smart WebStorm is.
00:00:08Â It automatically asks me whether I want to add it to Git.
00:00:11Â But for now, I'll cancel that because I want to explain everything manually.
00:00:15Â Let's make it simply run a console.log that prints hello Git.
00:00:20Â Alongside this file, let's create another new file and I'll call it readme.md.
00:00:26Â In here, we can do something similar and say hello Git.
00:00:31Â And now, run git status.
00:00:34Â Git will tell you that you're currently on the main branch, that there are no commits yet, and that there are two untracked files,
00:00:40Â one of which is a markdown document.
00:00:43Â So, to track it, use git add readme.md.
00:00:49Â After adding a file, we need to commit it.
00:00:51Â Committing in Git is like taking a snapshot of your project at a certain point.
00:00:55Â Think of it as creating a whole new copy of your folder and telling Git to remember when you did it, at what time.
00:01:02Â So, in the future, if anything happens, you'll time travel to this folder with the commit name you specified to Git and see what you had in there.
00:01:11Â It's essential to commit your changes regularly.
00:01:13Â Regular commits help you keep track of your progress and make it easier to revert to previous versions if you break something.
00:01:20Â You can commit by running git commit dash m, which stands for message.
00:01:25Â And then in single quoted strings, you can add that message.
00:01:29Â For example, add readme.md file.
00:01:33Â There we go!
00:01:34Â Congrats!
00:01:35Â You just created a checkpoint in your project's history.
00:01:38Â Now, let's try running git status again to see what it shows.
00:01:42Â As you can notice, that other file, hello.js, is still there.
00:01:46Â It's not tracked.
00:01:48Â We asked git to track only the readme file.
00:01:51Â To track this file or other files that you may create, we'll have to run a similar command.
00:01:56Â It'd be too much work to commit each file individually.
00:01:59Â Thankfully, we have a command that commits all the files we've created or modified that Git is not tracking yet.
00:02:06Â To see this in action, let's create another file.
00:02:09Â Test.js.
00:02:11Â And let's add a simple console log that simply console logs a string of test.
00:02:16Â Now, to track both files and commit them in a single commit action, we can do that by running git add dot.
00:02:23Â The dot after git add tells Git to add all files created, modified, or deleted to the Git tracking.
00:02:30 Next, as usual, we can specify the commit name for this tracked version by using git commit –m add hello and test files.
00:02:42Â There we go.
00:02:43Â So now we can see that all of these files are tracked.
00:02:46Â And since I'm using WebStorm, it also has a hidden .idea folder, so it added it to tracking as well, which I'm okay with.
00:02:53Â Well done.
00:02:54Â Now to see the history of all commits we've created, we can use a new command, git log.
00:03:00Â And there we have it, our git history.
00:03:02Â It contains a commit ID or a hash automatically created by git, the author we specified when using git config, a timestamp,
00:03:11Â and the commit message we provided.
00:03:12Â Thank you.
00:03:13Â Great, but how do we switch to an older commit and restore it?
00:03:17Â Let's say the commit add hello and test files introduces some buggy code, and we want to restore our project to a previous version without these files.
00:03:25Â Our brain would immediately suggest deleting those files entirely or clearing up their code.
00:03:31Â And if you do that, you'll most likely break your production because other files depend on those files.
00:03:36Â So instead of deleting them manually to restore to the first version where we had only committed the readme file, we can use a new command.
00:03:44Â First, you have to copy the commit hash.
00:03:46Â Yours is going to be different from mine, so make sure to copy yours.
00:03:50Â I'll get this one first that says add readme.md file, and I'll press copy.
00:03:55Â Then you have to exit this Git log by pressing the Q letter on the keyboard, and then you can use the command git checkout,
00:04:02Â and then you can provide a hash of a specific commit or a branch you want to check out too.
00:04:07Â Now press enter.
00:04:09Â Okay, something happened.
00:04:11Â First of all, our two files are gone.
00:04:14Â Detached head, experimental changes, what's happening?
00:04:17Â Well, in Git, there is a concept of a head, which refers to the pointer pointing to the latest commit you've created.
00:04:24Â When we created our second commit, our head shifted from readme commit to the latest add hello and test files commit.
00:04:31Â But when we ran git checkout command, we moved the head to the previous, older commit.
00:04:37Â That's why we got this detached head warning.
00:04:39Â It's a state where the head pointer no longer points to the latest branch commit.
00:04:44Â And the rest of this message tells you that you can create a new branch off of this commit.
00:04:49Â But don't worry, your files are still somewhere.
00:04:52Â When you use a git checkout command, you're simply viewing the repository state as it was at the time of a specific commit.
00:04:59Â Like right now, we're viewing a snapshot of your code base at a previous moment in time when we only had a readme.md file.
00:05:07Â The beauty of this is that all the logs and files, whether created or modified, remain untouched.
00:05:13Â The git checkout command won't delete any logs or history, so you can safely explore past states without worry.
00:05:20Â But what if you actually want to discard changes made after that commit?
00:05:24Â Maybe you want to quickly roll back to a stable state after an issue hits production, tidy up messy commits to look more professional,
00:05:31Â or undo a bad push you regret making.
00:05:33Â Perhaps you've been experimenting with a refactor that didn't pan out, or you need to recover from a messy merge conflict.
00:05:40Â Thankfully, Git provides a few commands that'll help you in these scenarios.
00:05:44Â and I'll teach you how all of that works very soon.
00:05:47Â So just keep watching and we'll dive into these more advanced commands that are really gonna help you, well, fix a broken production.
00:05:54Â Now, to go back to our current state, which is often called the head state, you simply have to run git checkout.
00:06:02Â And there we go.
00:06:03Â Previous head position was at the hash of this checkout, and now you switch the branch to main.
00:06:08Â You can see the same thing happen right here on the bottom right or the top left, depending where your branching is.
00:06:14Â And if you made any changes while in the detached head state and you want to discard them, you can do the same thing, get checkout,
00:06:21Â dash F, that means force, and then get back to main.
00:06:24Â In this case, we're good, we're already on main.
00:06:27Â And that's it.
00:06:28Â You already know more about Git than most developers do.
00:06:32Â Of course, we'll dive deeper into advanced use cases and tips and tricks soon, but now let's talk about GitHub and how it differs from Git.