🔥🔥🔥 Coming back with yet another short, snazzy and crisp article on the most used tool in today's world of code : Git (🤠Father) & Github (👶Son)
What is Git ? 🤠🤠ðŸ¤
It is a version control system. At its core, it is nothing but basically it is a ledger for saving your file's history and any historical changes made in the file.
Git Installation
- Visit Git
- Do not ask how to download it & how to choose the installation meant for your OS architecture type. If you do not know this, you probably are not even qualified to read this article.
- Open the downloaded setup, keep clicking on Next, Next, Next... till it installs in the default location with default settings.
What is Git Bash ?
- It is a DOS (Windows native) like command prompt terminal.
- Git Bash works on the Linux/UNIX architecture but it is emulated to work on Windows/MAC.
Open Git Bash
- Check Git version by typing :
git --version
- This is simply a basic check to see if Git was successfully installed or not.
Git Version should definitely show to ensure Git is installed. If not revisit steps above.
Configure your Git
- You must configure your Git with your username and email to ensure that everyone knows that is you who made changes to the file.
- It basically is like login credentials.
git config --global --edit
- Opens the git config file in your default editor : Notepad / VSCode / Atom etc. Edit the credentials here and save the file.
- Confirm the username and email
git config --global user.name
git config --global user.email
🥂🥂You are all set now 🥂🥂
#Start using Git for any file and any language : C, C++, Python, Javascript, HTML, CSS, anything... literally anything...
Go to your project folder
- Make the project folder as your Git Repo (Repository) :
git init
This basically initializes Git to make an empty repository at the project folder path.
- Makes .git folder which basically is a hidden git folder which tracks your project folder.
Git Status
- Check git status of your project folder as to what files are in the staging area, what changes are yet to be commited, what is commited, etc.
git status
🔨🔨🔨Staging Area Concept🔨🔨🔨
- Git version control is basically a 3 step process.
- Files are first brought to a place called Staging Area.
- Staging Area holds only those files you want to commit.
- From Staging Area, you would then commit the files to your Git repo.
Git Add
- Files are moved to staging area.
//Adds only a particular file or files to staging area.
git add filea
//Adds all files in current working directoy to staging area.
git add .
//Adds all files including sub-directories to staging area.
git add -A
Git Commit
//Initial or first commit , -m is for message
git commit -m "first commit"
Git Log
- To check what all past commits we have made as a historical log data.
git log
Git Checkout
- To travel to a past commit if need be.
git checkout <commithashcode>
- To revert back :
git checkout master
🌴🌴🌴Branch Concept of Git🌴🌴🌴
Git Branch
- We start with a master or main branch.
- We can then make new branches for our project.
- The
git checkout
command is actually used to jump from branch to branch.
git branch
- In production environment, several developers work separately on the code in their own respective branches so that the main code is not tampered with.
- To create a new branch:
git branch dev
- To simultaneously create a new branch and checkout in it:
// manik/design is just a name given according to the work user manik is doing on the project
git checkout -b manik/design
Git Merge
- To merger two branches.
- For example, code change in dev branch needs to be merged with another branch.
git checkout dev
git merge manik/design
Git Ignore
- To add some files which we do not want to track in git as in ignore those files.
touch .gitignore
- Now you may simply add the file names or folder names whom you wish to ignore.
Github👶👶👶
- We create Github profiles which basically hosts your code in remote repositories on the web.
- Go to Github to create your profile.
- People from all across the world can view your code, contribute and add functionality to it ofcourse after your permission :)
Creating new repo and linking to your Git
- Go to your repo tab and click on new to create new repo.
- Fill in the repo name and make it public/private based on requirement.
- Now all the necessary commands are already provided by Github to faciliating linking your local repo to the remote repo, its quite self-explanatory:
- Write necessary commands as per requirement on your local Git Bash terminal.
Pushing your local repo to remote repo
- It is a 3 step process :
Git Remote
- To check what is your origin to fetch or pull.
- Here your local repo branch is master and the remote branch is origin:
Git Push
- Used to push your local repo code to remote repo.
Collaborate with People
- You may add collaborators to your repo who can access and contribute to your repo.
- Manage access through the Settings tab below:
Git Fork
- If you wish to do open-source contribution you may check any public repo and fork it or so as to say get a
copy
of that repo in your remote account and make changes to that copy, not the original one. Top right corner has afork
option:
Git Clone
- Cloning means to get a copy of the forked repo onto your local computer and make changes in it.
- Now you make changes and commit to your forked remote repo.
Pull Request
- After you commited to your forked repo, you may wish to contact the original owner of the repo and send him a pull request so that he/she may merge your forked repo to the original repo, only if he likes your changes :)
- Now the pull request is sent to the original owner of the repo for approval.
Pull Request Approval
- The pull request is reviewed by the owner and if all good then is approved.
- Now the owner has the option to merge the approved pull request into the original repo :
🎺🎺🎺
So this was all about the concept of Git and Github. I know that this may be a bit confusing for beginners but trust me this is the fastest and crispest explanation I could give keeping in mind coverage of all important topics as well. These topics are enough to get you going in your coding journey :)
Adios amigos... 😄😄😄
Â