Learn Git In Few Simple Steps

Let’s learn Git in a few simple steps.

Step 1

Create one Repository on GitHub or anywhere you prefer.

Step 2

Install GIT.

Step 3

Clone the repo with the below command. You will get the repo link ending with .git once it will be created, just click on Download/Clone Button over there and copy the link.

Now cd to the clone directory below.

Step 3

Set your global Username/Email Configuration.

Step 4

To see the configuration do

Step 5

Now, do what so ever you want in that directory related to your project.

Step 6

Once done track the changes you have done by typing the below command,

Now, you need to commit the changes locally on your workstation.

Step 7

For committing the changes you need to add the changes locally, so use the below command to do that.

Step 8

Now push the commit to a remote branch.

Difficult and Tricky part for Newbie

Here come’s the interesting thing for you suppose you have created one branch from master and started working on it.

You have committed lot’s of changes and had pushed it to the remote branch.

Now it’s time to merge the branch to master but your manager told you that he will merge your branch only if it has one commit now you need to remove your rest of the commits from there.

How will you do now?

Here come’s the word SQUASH in Git.

You need to squash the commit with one, Let’s do it.

Tips

The simple solution is while requesting for merge you will get the total number of the commits, or go to the repo and check the number of commits you made on a branch.

Steps for squashing the commits

Create one branch by typing below command which will refer your master contents but separate from master until you will not merge the created branch.

Now, do as many commits required while working on your project for example,

I have done a total of 5 commits in my branch, to verify type the below command.

Push the changes along with your locally created branch to the remote repo.

Now you need to count your number of commits done but my suggestion is either you go for the hit and trial commits count or with Hash ID because If you have tons of commits to squash, counting will become a headache.

Now type the below command,

For example,

I have made 5 commits in my branch, so I will do

Now it will pop up an editor where you need to modify some changes

If you will go through the above content, you will find the option to squash, suppose I want all commit messages after “test” should merge in the single commit message, you need to replace “Pick” with “squash” or “s“, check it out below,

Note** Don’t put “s or squash before all commit messages”. You must leave one “pick” before your commit message to complete the procedure.

Now save the editor after making the changes.

Once you will save it, It will popup a new window again like below,

Delete all the commits message from here, and write one final message “task completed with final commit” like below, and save the file.

After saving you will see the output,

Now you need to push the changes on the remote branch with a single commit, for that type the below command,

Go and verify the number of commits messages in the remote branch, I hope for one there if you will find more then do comment. ๐Ÿ™‚ ๐Ÿ™‚

Now raise a merge request to master.

This time your Manager will definitely accept the request to merge in master after verifying the changes you have done. ๐Ÿ™‚ ๐Ÿ™‚

 

Askops
Askops
Developer: Nikhil raj
Price: Free

Leave a Reply