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. ๐ฑ
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 locallygit clone [url]๐ฅ
It's used for cloning the repository from your code storage platform locally into your systemgit add <filename>โ
Used to add files in the staging area,git add .would help in adding all the modified files in the staging area explicitlygit statusโน๏ธ
It shows all the files that have been modified and will be staged for the next commitgit 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 messagesgit diff๐
Helps in knowing what all changes have been made before pushing the files to the staging areagit branch๐
Gives a list of all the branches that were in the repository, highlighting the branch that you're currently working ongit log๐
Shows all the commits that were made in the current branch's historygit checkout -b <branch-name>๐
This command helps to create a new branch and work on itgit switch <branch-name>๐
Helps in switching the branch from the listed branches in the repositorygit 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 fetchvsgit 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! ๐

