You Should Know This Git Commands | Part 3

You Should Know This Git Commands | Part 3

In the Article about the intro about Github and Git, and also the features of Github. We learned about Github, But there is a command-line interface called Git by which we can interact with online repositories like Github, bitbucket, etc. Let's see in detail about them.




What is Git? Why should we learn it?

                Git is a Version control tool maintained by Linux, and it was created by Linus Torvalds who is the creator of the Linux kernel also. It is used by many open source technologies to maintain their software which is being developed by people around the world. Instead of Working on a single version of software GIT allows developers to work on different versions of the software simultaneously and also maintain them easily. And it is also highly secure, fast, and flexible.

                Using Git we can easily manage multiple software and versions, we can also keep track of the changes made in the application. Operations like merging, pulling, pushing, committing can be done securely and easily with GIT commands. The version control feature can be understood with a simple example, suppose you developed software that has 2 versions, 1.0.0 and 2.0.0. Now one of the developers needs to work on version 1.0.0 and fix a buy, so using GIT he can easily work with the version without affecting the functionalities for version 2.0.0, Because when the developers work on version 1 a new branch or piece of the block will be created which will be isolated from others if after completion there are no errors this block can be added to the main branch for production. So that's why GIT is perfect for this job.

Let's start with learning the Important Git Commands.

1. git init:

 It is a command to start with a repository this is sometimes can be replaced with a git clone if we are working with some other command. For this first, we need to go to the folder where we want to create a repository in the terminal and type this command.


2. git clone:

This command can be used when don't have a repository to work with, but we are working on some other repository that is not present in our folder. In simple words, it's like making a copy of an online repository that is present in GitHub or bitbucket into our local machine and start working in it.

The syntax of this command is git clone repository_line


3. git remote add origin

This command is used to set up the repository which is present in our Github account and which we are working on. For this, you need to give the credentials of your GitHub account to use this command. In the last article, we created a Repository called myFirstRepo we shall be using this repository for demonstration, you can work with any repository.

  • => git remote add origin <repo-link>


So in the above picture, we can see that I have set the origin to myFirstRepo repository and also cloned the library into my local machine, in this way we can clone the repository, before cloning the folder has only one folder called "New Folder" after cloning all the contents of the Repositories are added into a folder with name same as repository name or myFirstRepo.


In the above picture, we created a new txt file with the name myNewTextFile using PowerShell command "New-Item" and added data to it using the "Set-Content" command.

4. git status and git add .

This command can be used to see the status of the files which are needed to be committed into the repository, by using the git add command we can add files to the staging area where the files are ready to get committed.

  • => git status
  • => git add . (or)
  • => git add myNewTextFile.txt


5. git commit -m "message

This command is used to make the commit into the main repository but the changes will not reflect in the main repository by now, you can see the log using git log  --oneline command. By using the commit command a new node is created which can be pushed to the git repository.

  • => git commit -n "my new commit_message"


6. git push

This command will reflect the changes into your repository after using this command all the files and modified files will be reflected in the repository.

  • => git push 
  • => git push -u origin branch_name


We can verify this by seeing the repository. In the picture below we can see that the text file has been added to the repository with the message we gave in the command line.


7. git branch

Sometimes an application might have different branches for different versions for adding into a specific branch we can use this command for pushing into a branch we can use the command.

  • => git push -u origin branch_name

8. Additional Commands

Apart from the above useful commands, there are some commands which can be helpful while working with git, they are.

For Creating a new Branch 

  • => git checkout -b myNewBranch

For Listing all the available branches we can use the command, we can add additional attributes to this command like -r, -a, which will list all the branches and working branches briefly. 

  • => git branch

 Merging the Current Branch to one of the branches we can use this command.

  • => git merge branch_two_name

Deleting a branch we can use

  • => git push origin --delete branch_name

Post a Comment

Previous Post Next Post