? : What is Git? 🤔
Git is the version control system that maintains the code-base of your project. At every stage, if you change some part of the code. It can keep a record of what was changed to avoid any errors. And also to get back to the stage where the code was working fine.
Still Confused ?
Don't worry let me Explain | 😃
Git Git is an open-source version control program. It helps you to keep track of your project code. So, that if multiple people are working on the same project. Then you can check which person did work on the project. Also, what changes were made by the person?. But wait, that is not it. You can also track all the changes that you have made. If I tell you that you can go back in time to the previous code-base that you just removed. And want to revert the code-base you can get to that isn't that be interesting. Don't imagine too much 😅 it's just a time machine/history for your coding changes only.The changes will be automatically by git. If something goes wrong, you can go back where everything was working perfectly.
Git has several commands let's try them out.
- First, try to create a folder so that every file is tracked in it and your work didn't mix with other files.So,lets try it on some files.
First initialize git by command.
But you won't see any git file inside the folder for that use ls -a to see all hidden files.
You can see the hidden files in above picture attached.
The red writing means that it is not in the staging area so by git add. It can become of color green indicating that it is now in the staging area.
git status #this will show the Untracked files git add . #this will add all the files to the staging area where it can move forward for commit stage.
Then do the first commit by command:
git commit -m "first commit" #-m means message you can write any message.
To check if the commit is made or not try :
git log # All commit Information
try running git status then you will see that the tree is empty:
After making some changes to file and created a log for tracking.
cat filename # Read what's inside the file
If you want to unstage something that you mistakenly staged you can used following command :
git restore --staged file.txt # Read what's inside the file
See it became from green to red color indicating that it is unstaged.
Deleting file from folder : use command : make sure to commit so if you need your file back you may get it.
rm -rf file.txt
To get it back you will first have to delet the last commit.To do that just do git log and select the second last hash key or if you want to delete 2 commits then select the commit hash key before the last 2.
git reset hashkey #this will delete previous commits.
As just delete the previous one so using git log:
After that do the following things:
git status git add . git status # to check wheater stage or not.
git stash git add filename # to check wheater stage or not.
then u can commit this as well to keep record.
git stash clear #to clear the stash changes permanently
#Now Github Part
Go to Github create repository for example I created like :
Now to add it to local project use command:
git remote add origin url #of your repository
just copy it and past then use
git remote -v #to check all the attach urls
Now use push command:
git push origin master
after that it will ask you for your Github name and pass.
If received an error don't worry just go to Github setting then developer settings then generate token.
But wait select some option as well. Like in the picture given bellow:
then generate and copy it follow the same previous push command then instead of using password use the token and paste it there as a password. Finally done:
File.txt is uploaded:
Some extra things related to Github: Branches:
You can create branch in order to avoid any changes that directly affect the main branch which is already verified so branch help us to created another path of the same code-base but once every thing is finalized you can merge it with the main one.
git brach new #created new branch git checkout new #switched to new branch
Now the next part how to create a pull request: Steps to follow first forked It: Using the fork option top right left then try to use the url of the main repo with command : But first clone it: using
git clone url #of repo it will clone it inside the folder
After cloning: use:
git remote add upstream url#now use the main repository url from where you forked it not yours. git remote -v #to check connections
Now after doing some changes in the file :
git status #tells the changes git branch new #create new branch git checkout new #shift new branch git add . #added all the changes git commit -m "message" #commited git log #to check the commit and it will show #that head-->branch means that new branch commit
Now use command :
git push origin branch name # Name and pass of #github will be required add and done.
Two branches has been created and also pull request button is also showing :
Pull request click it and finally created your request:
waiting for main repository person to merged:
Recieved at the Main repository:
After reviewing it will be merged!
The change can be seen as I added updating the main repository!.
Hurray congrats on your first pull request merge🥳!
Just try for yourself by adding a comment in repo Git I would be happy to merge it for you😄!
Download the cheat sheet for Git_download for the reference. Thank You for reading! See you next time with some interesting Topic to talk about😁!.