Lets understand Git & Github:
It is a Distributed version control system which tracks various changes of the project files and maintain logs and we can any time jump to our previous data code and this is very fast and reliable.
GitHub is a global company which provide hosting for software development version control using Git. It was acquired by Microsoft in the year 2018.
Lets dive into, it's commonly used commands:
Starting with git , Git is version control system tool (vCS).
Mostly used git commands:
git init is used to initialize an empty repository in our local machine
This command is used to move our file to the staging area
This command checks the staus of all the files present in our repository and display them
git add -A ( here hyphen with capital ‘A’ is used to add multiple/all (is same as ‘–all’) files to staging area)
git commit -m “related message” ( commits all files that were in satging area and hyphen m is required for related description(or any related note)
‘git init’ is basically used to initialize a repository and creates a local repository in the folder where we executed “git init” command .
Once this is done, .git folder is created and is, by default hidden(goto ‘view’ tab, click on show hidden items ) in the specified folder
git add’ commad is use to move our files to the staging area or we can also say that here files are getting added to the index file which is necessary before commiting any file.
‘git commit’ command is used to add all/multiple files that were in satging area and hyphen m(-m) is required for related description(or any related note)) and if you wanted to commit some files but not all then after git commit command enter multiple file name as shown here (git commit some.txt some1.txt some2.txt folder/some4.txt -m “commiting 4 files”) this would then commit the provided four files only.
git remote add origin
‘git remote add origin “type/paste origin url here” ‘ this command adds the url of our git repository, you would find this URL under ‘clone or download’ button(green colored) in your repository section, in git hub Account.
git push origin master
‘git push origin master'(branch name) this command pushes the code to ‘master’ branch, as specified master in branch name here, it can be any branch name then file’s will be pushed to that branch.
git pull origin master
‘git pull origin master'(branch name) this code pulls the files from the central server(central repository).
git is a Distributed version control sysrem (DVCs) and it becomes easy to execut all others command except push/pull because it would then call the central repository, Dvcs refers to the distributed version control system that means we at our local machine also have the cloning of the main repository that is present in the git hub. so it becomes easy and also we can work offline mostly until required to push or pull the code .
Branching in git:
Talking about creating branches, Because of multiple branch creation, multiple persons can contribute or work for a single project by creating multiple branches of the master branch, what we are getting is a copy/cloning of masterbranch data upto that period/time, and everyone can work on their part of module and finally merge.
In merging section, we simply need to be aware that we are checked out in destination branch , once we are than we can simply perform the merge command i.e
‘git merge branchname” so after this command execution the branchname(mentioned branch) merges to the branch in which is currrently showing in terminal, so it is very important to checkout/switch to the branch, where we are merging this.
git log are created which in turn stores the version, in form of all the changes in our project code files like recommiting after changes so in this case previous commit record is saved in log in form of version and when git log command is executed it shows all logid’s of changed files and we can access or go to that previous change by using first 8 character of that file log id(as shown in git logs) we can revert back to previous version.
Below is a git command to revert back to previous version.
‘git checkout 8character–id filename’
Once the above command is executed it reverts back that particular file to that previous log state/previous changed state.