Git command (add, commit and push)

How many times this has happened to you when you are making a project and you decide to add your project to Git or GitHub to keep track of the version(version control)?
This old git meme is the perfect example to understand the command.
Git add
Understand git add for adding the file to git as Passangers🧳 boarding the plane before taking off.
The syntax for git add is simple git add file.ext
git add index.html
git add script.js
A good shortcut for adding all the files is adding the period(.).
git add .
Git commit
Unlike git add git commit can be a bit confusing.
Let's take an example for git commit, just like a painter🎨 while making a perfect shade of colour goes through multiple stages and keeps the sample of previous shades for maybe future uses. Just like those intermediate shades, we commit our changes to Git.
If we feel that the previous version was better so we'll check out the previous branch and go to that version.
The syntax for git commit is git commit -m "_commit message_"
git commit -m "added css"
git commit -m "added css" -m "css with hover and animation"
You can add one -m flag to add a commit message or two -m second one for a detailed description of the commit.
Shortcut for adding and committing at the same time
If you have not added any new files to the folder and you want to commit new changes you can use the -am flag
git commit -am "updated css"
Adding your code on the web (remotely)
Till now we have learned how to keep track of file changes(version control) locally.
Now we'll see how to add a remote location for the files and file changes.
There are multiple options for the remote repository(folder📁) such as GitHub, GitLab, and Gitea... But we'll look at the most popular one GitHub.
Before pushing your plane(remember the meme) with the change to the remote location there is a small step of defining the location
Git remote add origin <url-for-remote>

git remote add origin https://github.com/username/new_repository.git
Git push
The final step of our today's blog is git push, just like the meme above push is similar to the final take-off of the plane.
The syntax for it is,
git push orgin master
A simple shortcut shortens the push process every time we use push, add -u flag which stands for upstream.
git push -u origin master
if we want to push to master every time, we use -u flag after using this flag now we just need to write git push.
git push
Lastly, in the example i'm using master branch everywhere but it can be different in your computer, these are just the commands you need when getting stated with version control. there are many more commands like pull,merge,clone,fork we'll discuss that some other blog.
If you want to know more about git commands Click here for well explained Youtube video

