Muhammad Waqar
codeminions

codeminions

Git and Github for Beginners - Creating your very first Pull request ๐Ÿค“!

Git and Github for Beginners - Creating your very first Pull request ๐Ÿค“!

Hacktoberfest Pull request

Muhammad Waqar's photo
Muhammad Waqar

Published on Sep 27, 2021

5 min read

? : 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 ? Gif

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.

  1. 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.

git init

image

But you won't see any git file inside the folder for that use ls -a to see all hidden files.

ls -a

You can see the hidden files in above picture attached.

2

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.

3

Then do the first commit by command:

git commit -m "first commit" #-m means message you can write any message.

5

To check if the commit is made or not try :

git log # All commit Information

545

try running git status then you will see that the tree is empty:

git staus clean

After making some changes to file and created a log for tracking.

image

cat filename # Read what's inside the file

read file git

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

git unstaged

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

deleted

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.

Untitled design

git reset hashkey #this will delete previous commits.

image

As just delete the previous one so using git log:

image

After that do the following things:

git status
git add .
git status # to check wheater stage or not.

image

git stash
git add filename # to check wheater stage or not.

image

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 :

image

Now to add it to local project use command:

git remote add origin url #of your repository

image

just copy it and past then use

git remote -v #to check all the attach urls

image

Now use push command:

git push origin master

after that it will ask you for your Github name and pass.

image

If received an error don't worry just go to Github setting then developer settings then generate token.

image

But wait select some option as well. Like in the picture given bellow:

image

image

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: image

File.txt is uploaded:

image

Some extra things related to Github: Branches:

image

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

image

Now the next part how to create a pull request: Steps to follow first forked It: image 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

image

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

image

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

image

Now use command :

git push origin branch name # Name and pass of 

#github will be required add and done.

image

Two branches has been created and also pull request button is also showing :

image

Pull request click it and finally created your request: image

waiting for main repository person to merged: image

Recieved at the Main repository: image

After reviewing it will be merged! image

The change can be seen as I added updating the main repository!. image

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๐Ÿ˜!.

ย 
Share this