In layman's terms, Git is a distributed version control system created by Linus Torvalds created git
in
2005.
You might be wondering what this version control is? Don’t worry, folks, I’ve got you covered.
Version
control or source control is a practice of managing and tracking the changes to the program code.
So,
it’s like a tracker that tracks every change in your code. You can commit the changes when needed
and
revert to the old changes as well.
Let’s talk about GitHub now.
To use the git bash (the command shell to enter the git command) you need to first install the git
To install the git on your device. Click Here
You can set the user name and email for the first time you use git after installing it or also can update it though:
git config --global user.name "Your Desired User name"
git config --global user.email "Your Desired email"
You can see your username and email that you set at any time by the command
git config --global user.name
git config --global user.email
Whenever you start working on a project and you want to use git functionalitities and features in it then you will first have to initialize this floder:
git init
Now you can run all the git commands in this folder.
This command will create a hidden folder .git in the folder in which you opened and run the git init command
To see the hidden You can run ls -lart command
To check the status of your file you can use the following command
git status
untracked file means: Either You have not added these files to the git or you have modified them after adding these files to the git
You must have to add add all the files to the git if you want to track them and commit them
commit means: that the added/tracked files can be pushed to the remote directory on some VCS hosting server like github or big bucket
To add or start track a new file/folder or modified file/folder that was already added ,you can type the following command:
git add -A (To add all untracked files and folders in the working directory)
git add . (To add all untracked files and folders in the working directory)
git add "file/folder name or relative path" (To add only selected untracked files and folders in the working directory)
You can commit (make files ready to push) the files that are being tracked (i.e that has been recently added to the git only) by using the following command
git commit -m "Type any message here relevent to your changes before this commit as notes"
You should check the git status repeatidly: After every add and commit because you often makes changes and add new files to your folder
If you create a new file or make changes to some file then only the files that were added to the tracked file will be commited and to add the new file/s too then you will have to add these untracked files also to the git by the git add command described above.
You always make changes in your project and you can commit as many times as you want after modification in your project and add notes for that commit./p>
To see all of your commits, you can use the following command:
git log
It will show the all the commits and the notes corresponding to that commits you added in a sequence with the date and time and all other details
You can use the following command to add and commit a file at the same time:
git commit -a -m "Type any relevent note here that you want and most relevent to this commit"
Note: This command only work for those untracked files and folder that were at least once added with the git add command as described above and will not work for a newly created file or a file that was never added before for tracking.
You can push your whole git working directory to the remote repository you created on the githud or girbucket etc. by using the following command:
git push -u origin master `write here your github/gitbucket etc repository path that you created`
To create a new repository on github you need to create a free/premium account on github and create a new repository their
Before using push command you will have to connect your git and github account by generating an SSH key. To know the method click Here