When a 10-year-old asked me what are Git and GitHub?
Imagine you have an application or project folder and you want to collaborate with other people on that project or you added a new feature for your application, now due to some mistake your application stopped working like it was before. Now if you want to go back in time to the codebase in which that application is running Git will help you to do that.
In other words, Git is a bookkeeping mechanism where in you keep records of what changes has been done on top of each other so that you can remove those changes and you can go back to previous versions.
So this is the whole idea of why we are using Git and GitHub, it will also tell you who did it? and what he did? when he did? so that you know what are the changes that lead to this output and you can go back and forward in time.
You can use Git in 2 ways by using its app(Git desktop) or through Terminal/Git bash
Terminal: The terminal allows the user to manipulate file structure using commands.
These are some Linux commands: For git
git - To check if the git is installed or not.
If you get a list like this that means Git is currently Installed.
dir - This command is used to list all the things in the folder
mkdir filename(make directory) - Creates a folder
cd filename(change directory): Command used to go inside the folder
In simple terms-it means double-clicking on the folder by using the command line so that you can go inside it.
Maintaining the History of your project using git.
First, where is this history stored?
So all this history is stored in another folder that git provides us. This is known as git Repository and it is named .git and this folder is hidden.
dir /a:hd - shows hidden files in the folder
dir git- to see what is inside the hidden file
git init - Using this command the history of the project or any changes that are made in the project git will pick it up.
type nul>filename - to create a file in a folder
git status: Using this command we can see what all files/codes have been changed, modified, added, or deleted in the folder.
Untracked files: when you are using git status, you might come across this term, which means files that are not saved in the history or not in the git repository.
- git add . or git add filename: using this command you can add untracked files to git repositories.
In this command, there is a full-stop / ' . ' which means everything in the current directory that is currently not tracked or untracked.
git commit -m " your commit statement inside this double quotes " - This command is used to save it permanently in the git repository or git history.
For example git commit -m "Initial commit"
Here ' -m ' means it is telling us to provide a message and the message is written inside the double quotes(" ").
git log - commands used to see the entire history of your project. (all those commits that are made in history)
del filename - used to delete a file
Then you have to use git commit -m to save this change.
Getting started with GitHub
Create a repository on the GitHub website
You will get a URL for your new repository
- git remote add origin URL - This command will attach the command to the local project.
Here 'git' is the Git command
'remote' basically means that you are working with the URL
'add' means you are adding a new URL
'origin ' means the name of the URL that you added
git remote -v - used this command to show all the URLs that are attached to the folder
git push origin branch-name - This command is used to share the change in that URL.
Then you have to refresh the GitHub page to see the added folder to it.
Use of Branches: Whenever you are working on other features, new features, or resolving a bug always create a separate branch.
You should never commit to the main branch of any project in the open source.
branch 'main' is the default branch
How to contribute to other projects in the open source?
First, you have to Fork a repo/repository
Fork: Forking a project is similar to this i.e. having an e-copy of the current version of the project on your own Github profile.
- git clone URL - this will download the folder in your local desktop
URL- of the forked folder in your account
git branch branch-name - As you cannot commit on the main branch you have to create a new branch by using this command
git checkout branch name - head will now come on this new branch
Pull Request:- when we send the changes from our GitHub repository to the original GitHub repository so that the project owner can see and review the changes. In other words, In GitHub, a pull request is a feature that allows developers to propose changes to a code repository hosted on the platform. A developer creates a new branch in the repository to make their changes. This allows them to work on the changes without affecting the main codebase.
This is the process:
Once the changes are complete, the developer creates a pull request by opening a new request on GitHub. They can include a title and description of the changes made, as well as any additional information that may be helpful for reviewers.
Other developers on the project can review the changes by looking at the code and commenting on the pull request. They may suggest improvements or request additional changes to be made.
Once the changes have been reviewed and approved, the pull request can be merged into the main branch. This means that the changes will be incorporated into the main code and become part of the project.
Here are a few that are worth checking out:
Git Cheatsheet — http://ohshitgit.com/