What is Git?
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
You can download git from here : Git Download
Difference between Git and Github
People often confuse git with github or vice-versa, but they both are very different. Git is a version control system that lets you manage and keep track of your source code history. GitHub is a cloud-based hosting service that lets you manage Git repositories.
Let's take a look at some basic commands in Git
1. git status
This command is used to check the status of your git repository. It list's the files are staged, unstaged and untracked.
The above output will come if the repo has not been initialized before.
This is when the repo is initialized.
2. git init
This command is used to initialize an empty repository on your local machine. It will add ".git" hidden file to your project which will keep track of all changes in your project.
Open the project directory in the terminal and run this command to initialize your repository.
Output would look something like this.
3. git add
This command is used to add files in your git repo. We can add files using their specific name like git add readme.md
or else if we want to add all files together, then we can use git add .
.
Output would look something like this. This will all the files in the staging area. If we run the git status
now, it will show us something like this:
4. git commit
This command is used to commit the staged files in the repo. We can add a message to the commit by using -m "Initial Commit"
. Adding a message is very important as it will tell us about what changes where made in that particular commit.
Run git status
to check the status. It will look something this like
If it is your first commit, then after commit we need to run git remote add origin {the link which we get from github}
, this will tell the git to push the changes in the specific repo specified.
5. git push
This command is used to push the committed changes to the repo. If you are pushing the code for the first time then you need to setup git and github. You can checkout how to setup git from here
Run git push -u origin master
to update your code.
And done!!! You have successfully push your code to github or any other platform you may be using.
These were some basic Git commands which are commonly used. Surely there are many more explore. You can explore more of them here (references for this article) :
Also you can run git help
in the terminal and it will give you all the commands.
Thank you for reading this article, I hope you have learnt something new and valuable. See you in the next article!