Git Commit -m "Start learning git"
Basic & most useful commands to know about git..
Are Git and GitHub Same ?๐ค
Honestly, when I heard the names I thought they are synonyms but they are not ! Not even owned by the same company. So what are Git and GitHub exactly, and what is the difference between Git and GitHub as software tools and services?
Git is a free, high-quality distributed version control system suitable for tracking modifications in source code in software development. It was originally created as an open-source system for coordinating tasks among programmers, but today it is widely used to track changes in any set of files.
Github is It is a web-based Git repository. This hosting service has cloud-based storage. GitHub offers all distributed version control and source code management functionality of Git while adding its own features. It makes it easier to collaborate using Git.
README.md - The Magical Wand ๐ช
It's a special file that is widely used for the purpose of documentation. Even though you are not a programmer you can still understand what the project is about and kinda human-readable text is present in this file. It connects the user with the developer.
Pick up those pebbles ๐
Installation ๐ฉ
While extracting the file leave the options as default or you can change them accordingly.
Git comes with the GitBash which is similar to the command prompt.
Now let's get started with the commands ๐ When you install the git. Firstly, you need to register yourself there. to do so -
git config --global user.name "Your Name"
git config --global user.email "youremail@yourdomain.com"
Now, to check you have successfully registered or not run-
git config --list
git init
This commit is used to initialize the git repository. The repository is a link or directory where you work on the projects.
git init
git add
3 basic parts of the git -
- working directory (where you are currently working at)
- Staging area
- commits To understand it in a simpler way consider an analogy of taking the picture for the wedding album. The people standing in a queue are in working directory.
The one who are taking pictures with bride and groom on the stage are on staging area once they stand properly we capture the picture means pushing them from staging area to the final picture means our repository
Commits are the instructions that tells what and how to do something.
git add .
It adds all the files to the staging area.
git status
It tells the current scenario. what's going on in general.
git status
git commit
Pushes the files from the staging area to the repository.
git commit add -m "msg"
Tells history. what commits you made and all.
git log
VS code tips
VS code directly provides you the support to directly run git commands

git remote
connect ur local project to GitHub repo
git remote add origin URL
git remote -v
git remote show

git push
Push the changes to the GitHub repo.
git push origin master -u
git pull
sync changes of the remote repo to a local one
- Fetch the changes from the repo.
git fetch
- Merge your changes.
git merge origin/master
Combination of fetch and merge
git pull
git clone
It is used to make a copy off github repo and its content on your local machine.
git clone "repo URL"
GitHub Codespaces
It is the cloud-based environment for the VS code. GitHub Codespaces run on a variety of VM-based compute options hosted by GitHub.com, which you can configure from 2-core machines up to 32-core machines. You can connect to your codespaces from the browser or locally using Visual Studio Code.
git branch
The branch is your own directory you can work on..
git branch
rename branch
git branch -M main
Create new branch
git branch branchName
Delete a branch
git branch -d branchName
By using capital 'D'. It deletes the changes on master branch as well.
git branch -D branchName
Fork
It's a copy of someone else's project that you can work on. As you don't have any rights to change the original project you can make changes here and create a pull request(kind of permission). If that pull request gets accepted your changes will be merged to the original project.
Merge Conflicts
When you make any changes to the forked repo and on the same file and line someone else make the changes then the merge conflict arises as the git gets confused about which changes should be taken. They are handled inside the VS code editor inside the source control tool. Or you can use the following commands according to the need
Reset the changes you made. Don't use it if changes are pushed to the remote repo.
git reset
Reverts back to the changes
git revert
change the commit message of the committed commit.
git commit --amend
Save ur work for later without committing
git stash
git stash pop
git stash save pop post2
git stash list
Get this index using the git log command we learned earlier.
git stash apply index
Rebase
Rebase re-applies commits, one by one, in order, from your current branch onto another.An interesting option it accepts is --interactive (-i for short), which will open an editor with a list of the commits which are about to be changed.
git rebase master --interactive

squash
Squashing a commit in Git means that you are taking the changes from one commit and adding them to the Parent Commit. Means binding them together.
git merge --squash
๐ฒ ๐๐ถ๐ ๐ต๐ฎ๐ฐ๐ธ๐ ๐๐ผ๐ ๐๐ต๐ผ๐๐น๐ฑ ๐ฑ๐ฒ๐ณ๐ถ๐ป๐ถ๐๐ฒ๐น๐ ๐ธ๐ป๐ผ๐.๐
Read this LinkedIn post made by my friend Om Gawande.
Kinda like a cheat sheet for the git commands that are rarely known but a hell lot useful.
