Skip to main content

Command Palette

Search for a command to run...

Quick Git Commands ๐Ÿง‘๐Ÿปโ€๐Ÿ’ป

Updated
โ€ข3 min readโ€ขView as Markdown
Quick Git Commands ๐Ÿง‘๐Ÿปโ€๐Ÿ’ป

Git, an open-source and complimentary distributed version control system, is engineered to effortlessly manage any project size, from the modest to the colossal, delivering unrivaled speed and efficiency. It was introduced in 2005 and is maintained by the Linux Foundation. ๐Ÿš€

Git vs Github โš”๏ธ

People often confuse these terms, and it gives interviewers an easy chance to poach the candidates. So let's first understand these terms:

Git is a free and open-source version control system that is not only limited to accessing GitHub but can also be used for accessing Bitbucket, GitLab, etc. Git is used to track changes in the source code, enabling multiple developers to work together on non-linear development. ๐Ÿ’ป

GitHub is a cloud-powered platform that leverages Git for version control and software development, facilitating the storage and management of code for developers. It can also be called as a code hosting platform for version control and collaboration. ๐Ÿ“ฑ

๐Ÿ’ก
Git can be used without GitHub, but GitHub cannot be used without Git!

So now, let's dive into the frequently used Git commands that are quite essential in day-to-day workflow:

  • git init ๐Ÿ†•
    This is used to initialize an empty repository and comes in handy when you're setting up a repository locally

  • git clone [url]๐Ÿ“ฅ
    It's used for cloning the repository from your code storage platform locally into your system

  • git add <filename>โž•
    Used to add files in the staging area, git add . would help in adding all the modified files in the staging area explicitly

  • git statusโ„น๏ธ
    It shows all the files that have been modified and will be staged for the next commit

  • git commit -m "your-message"โœ๏ธ

    This command is basically used to give a brief, one-line description of what the changes you made actually mean
    Checkout this page for writing good commit messages

  • git diff๐Ÿ”
    Helps in knowing what all changes have been made before pushing the files to the staging area

  • git branch๐Ÿ”€
    Gives a list of all the branches that were in the repository, highlighting the branch that you're currently working on

  • git log๐Ÿ“œ
    Shows all the commits that were made in the current branch's history

  • git checkout -b <branch-name> ๐Ÿ”ƒ
    This command helps to create a new branch and work on it

  • git switch <branch-name>๐Ÿ”„
    Helps in switching the branch from the listed branches in the repository

  • git remote add [alias] [url] โ›“๏ธ

    This command is typically used to link your local repository to a remote one. Commonly, it's used as git remote add origin [url], where 'origin' is the standard alias for your remote repository URL.

  • git fetch vs git pull ๐Ÿ“ก
    The git fetch command first fetches the changes from the remote repository and then stores the changes in a separate branch in our local repository.
    On the other hand, the git pull command pulls all the changes from the remote repository to our corresponding branch of the local repository.

  • git push โฌ†๏ธ

    Pushes all the changes made to the files present in the local branch to the remote repository branch

  • git stash ๐Ÿ’ผ

    Saves the current changes while you want to switch to a new branch and keep the changes staged

I hope you theoretically learned about these commands, would strongly suggest that practically implementing them would help you know things better. ๐Ÿ’ช๐Ÿป

PS: Just keep in mind no subconsciously git rm rfing things xD, I still remember how I deleted my whole project instead of deleting a file. โ˜ ๏ธ

Cheers, Practice well! ๐Ÿ˜ƒ