LongCut logo

Every Git Command You'll Actually Use - Explained in 4 Minutes

By Technophile

Summary

## Key takeaways - **git init turns folders into watched repos**: git init transforms a normal folder into a git folder, and from that moment on git watches everything you do inside it. [00:07], [00:13] - **Commit messages must explain the change**: The commit message name should tell what you actually changed so other developers can understand without reviewing your code. [00:58], [01:08] - **git reset --hard has no undo button**: git reset --hard deletes everything after a commit as if it never existed, and there's no undo button, so use it carefully. [02:02], [02:10] - **git revert rewrites without erasing history**: git revert creates a new commit connecting a past change to your current code without rewriting history, unlike reset. [02:17], [02:25] - **Branches are parallel timelines like Doctor Strange**: Branches let you create new timelines to experiment without ruining your main one, and you can create as many as you want. [02:25], [02:41] - **Tags are video-game checkpoints**: Tags mark milestones like checkpoints in a video game, and people commonly name them using semantic versioning. [03:23], [03:40]

Topics Covered

  • Commit Messages Should Communicate Without Code Review
  • Three Commands for Rewriting Git History Differently
  • Branches Are Doctor Strange's Parallel Timelines
  • Tags Function Like Video Game Checkpoints

Full Transcript

git config. After installing git, the first thing you need to do is tell git who you are. Just type this in your terminal. Get in it. This command turns

terminal. Get in it. This command turns your normal folder into a git folder.

From now on, git watches everything you do inside that folder.

Get clone. Want to copy someone else project from GitHub? This command helps you do that. While you can also just go and click on download in GitHub. This

one looks much cooler. Get add. Once you

have made changes to your folder, whether it's creating, modifying, or deleting, now it's time to save your changes in your machine. Pay attention

in your machine, not in GitHub. G

status. If you forgot what you have changed, you can use this command to check the history or type this command to see unsaved changes or better just

click on this icon in VS Code. It shows

all the details in nice UI. Git comet.

Before we put all those changes on the internet for others to see, we need to give it a name. Often times the name aka message should tell what you actually

change so other developers can understand without reviewing your code.

Get push. Now it's time to get your code to GitHub. Get pull. If someone else

to GitHub. Get pull. If someone else changed your code and pushed it on GitHub, it won't magically appear in your computer unless you write this

command. GitLo, you can view all your

command. GitLo, you can view all your past changes, see your decisions, and regret why you started this project in the first place. And if you are enjoying

the video, you can always do get subscribe. Thank you. G check out. Now,

subscribe. Thank you. G check out. Now,

if you actually want to time travel to that specific change in the past, then use this command. Just note with this, you cannot change the history. Get reset

and revert. But what if you could change the history? Well, there are three

the history? Well, there are three options. Get reset hard. This basically

options. Get reset hard. This basically

deletes everything after the commit like it wasn't there in the first place. Just

be careful. There is no undo button. Get

reset soft. Unlike the first option, this one does not erase your history and keeps all your changes staged. Get

revert. Basically, it creates a new commit and connects that past change to your current code without rewriting the history. Now, if you want to be like

history. Now, if you want to be like Doctor Strange and want to create a new timeline to experiment with things instead of ruining your own, well, with

Git, you can. Any changes you make, commit and push remains on the timeline.

And the crazy part, you can create as many timelines as you want. Git branch.

It shows all the timelines aka branches you have created. Git merge. Once you

have experimented with those timelines, you need to bring back the lessons you have learned into your current one because why did you create a new timeline in the first place, right?

Also, just pray there is no merge conflict otherwise you are screwed. Get

tag. Hit a big milestone in your project. Tag it. Edit a new feature. Tag

project. Tag it. Edit a new feature. Tag

it. Fix it a bug that took you eight days to solve it? Tag it. Rewrote your

entire code base.

Tag it. Think of tags as checkpoints in a video game. And the cool thing with Git, after you have created those checkpoints, you can always come back to any one of them with this simple

command. Now, people use this semantic

command. Now, people use this semantic versioning to name their checkpoints. I

guess it's a common standard among community, but you can name your checkpoints whatever you want. Get help.

If you forgot everything I told throughout this video, well, that's what it's for.

Loading...

Loading video analysis...