Git and GitHub (Part-1)
Git and GitHub are two different things (but they are related), they are like coffee and coffee shop.
Git is a version-controlled system. The creator of Git is “Linus Torvalds” (Linux creator). Git always looks into our files (24/7) for changes. It sees what changes happen in the file and makes a record in the file system. And it can be any file: image, txt, doc, video, JS, python, any programming language file i.e. any type of file. Here change means — what is changed? where did the change happen? change in which line? change in what time? who changed it? etc. everything.
The best feature of Git is it took the different versions of the file. Ex: if I write a code, bring a change on it, and want to keep the new version as well as the previous version(unchanged) then git can be the best choice. Git is mostly used in coding. But we can use it for other works.
Git is tracking the changes in our local machine. Ex: Suppose me and my other team members are working on a project from two different computers on 2 different things of the project. And we are working from 2 different places so there will be 2 versions. Finally, after completing the work, we have to merge the whole thing, we will need a centralized space so that we can host the file changes, so after completing my task I can push and my other team member will push from his/her space. After that, we can host the changes in a centralized cloud source. This hostname is GitHub. There are more hosts like this. Ex: GitLab, Bit Bucket, AWS CodeCommit, Beanstalk, Google Cloud Source Repositories, etc.
GitHub is a Git repository hosting service that provides a web-based graphical interface. GitHub is now owned by Microsoft. It is the world’s largest coding community. Putting a code or a project into GitHub brings it increased, widespread exposure. Programmers can find source codes in many different languages and use the command-line interface, Git, to make and keep track of any changes. The importance of GitHub in the programming community/open source community is very high.
Uses of Git and GitHub:
When we work in a local machine → all works are Local.
The file we work with → Working Directory.
After completing the work → we put our works on the Stage.
The Stage is an intermediate thing so after completing the work and getting the final approval → it will be given to the Local Repository.
Local Repository is like a folder. And Remote Repository is like storage in the cloud server. The repository consists of different tracking information. There will be some types of files that Git can understand.
Remote: All works stored in the cloud. Ex: GitHub.
We can go to the cloud when we want to share files with others or we want to store them on the cloud so that we can use them on another machine. For this purpose, GitHub was invented.
Local Repository → remote (we can transfer files from the local repository to the remote).
Remote → other machines (we can transfer files from remote to other machines).
How does it work?
Open Command Prompt → Git Bash
To go back to the working directory:
At first, we have to initialize Git.
It created a .git named folder. This folder is mainly maintaining everything.
~ Some git commands ~
1. mkdir gitone (gitone → file name) → to create a new directory(folder).
2. cd gitone → cd command, also known as chdir (change directory) used to change the current working directory.
3. touch one.txt (filename) → to create a file.
4. clear → to clear everything from the window.
5. cd ../ → to go back to the working directory/previous directory.
6. git init(to do git initialization) → to create an empty git repository.
7. git clone URL/link (paste the link) → to bring repository from remote).
8. ls → to see the folder list of the current directory.
9. git status → to see the changes in a file as a summary.
Carry changes from Working directory to stage(Add):
To add the files from working directory to stage.
11. git reset → to go from stage to local.
12. git add . → it will add all the files from the current folder/directory (local) to the stage, it will not add the files from the main directory.
13. git add * → by using this command all the files will add to the stage except the deleted one.
If we delete → two.txt files from gitone folder and add four.txt files to this folder. Then this will happen.
14. git add one.txt/ git add myFolder/three.txt → to add an individual folder to stage.
15. git add *.txt → to add all .txt file to stage.
© Syeda Nowshin Ibnat