Skip to main content

Basic GIT commands line tutorial-for beginners and for developers with examples-computer science/Information technology


GIT Commands tutorial

->Watch this for FUN - Funny job interview

Are you getting bored with online lectures?

->Watch this - When online lectures are boring 

Hello Everyone and welcome back to learn one of the most wanted skills in today's world i.e. GIT.
Now we'll gonna start with the basic git commands tutorial.
So, let's get started.


<><><><><><><><><>
First of all, what is git?
Git is a free and open-source distributed version control system designed to handle everything from small to very large projects.
Its command-line provides various operations to perform the various tasks of any project. Almost every online project in this world is built with the help of git and its command line.
By learning git you can expose yourself to the current and fastest-growing market skills.
It is the skill that every developer should have, to sustain and grow with the current tech market.

<><><><><><><><><>
Installation of the git:
Although there are various ways to work with the git, this section would show you the simple steps to get it installed in a few seconds if the network connectivity is at its best.
Step 1.Go to https://desktop.github.com/ for downloading GitHub on your desktop.
Step 2. Once you are done with the installation, now you can work with git, clone any repository, make a pull request, pull the changes, or push the changes, these can happen with the help of Graphical user interface too but the main motive to work with git is to do all these things with the help of its command-line interface.
Remember this installation is only for you to know the changes made in the repository that you have cloned or view the commits that have been made so far without going to google and view them.
The terminal or the bash is yet to be installed which is our 3rd step.
Step 3. Go to https://git-scm.com/downloads for installation of the git bash and do the necessary set-up and now you must be curious to learn the basic commands used for executing the necessary stuff on the command line. 


<><><><><><><><><>

Now let's look into its Command line.
1. Git --version
This command is used to check the version of the git on your computer.


************
2. Git init
This command is used for initializing your working directory.

************
3. Git clone
This command of git is used to clone the repository into your local system.
The format of it goes here :

                                          git clone name of the repository
The idea of cloning is to copy the source code into your local computer.


************
4. Git remote -v
This command is used for checking the current remote repository on which you are.

************
5. Git add
This command is used to add files in your working directory into the staging area to be committed to your repository.
************
Staging area :
Working directory>>>>git add>>>>staging area>>>>git commit>>>>repository

************
It can be done using the following two commands :
(a.) git add the name of the files
Well, this command becomes quite inefficient when there are a lot of files to be added to the staging area. Hence to avoid this we use,
(b.) git add .
This (.) that we use adds all the files in the working repository to the staging area.

************
6. Git commit
This command should be used when you are committing anything to the remote repository after adding to the staging area.
The syntax for it is:
                        git commit -m "a message"
                                           Well, this -m shows the message to be given as to be there with the commit.
************
7. Git push
This command is used to push the changes to the current repository.
The syntax goes as follows:

                                   git push/git push origin master
In case if the above doesn't work out then run:
                                   git push -f origin master  to force the changes.

************
8. Git status
This command is for checking the status of the current repository. It tells you about the current status of the files which are committed, on which repository you are, etc.
Run git status for above.


************
9. Git pull
Run this command to pull the changes made in the repository. You can also run
                  git pull origin master/git pull -f origin master

************
10. Git commit -a
Well, this command is used for staging the files, the files which are modified or deleted, but the other files are untouched.
Run git commit -a for above.

************
11. Git branch
This command is for checking the branches available for that repository.

(a.) Run git branch for above.
(b.) Run git branch name of the branch to create a new branch (locally).

(c.) Run git push --set -upstream origin branch name to create a new branch (globally).
(d.) Run git checkout name of the branch to switch to the branch.
(e.) Run git checkout -b name of the branch to directly switch as soon as a new branch is created.
(f.) Run git push origin --delete name of the branch to delete the branch globally.
(g.) Run git branch -d name of the branch to delete the branch locally.



************
12. Git stash
It should be in use when let's say you are working on a file for which you want to commit the changes later on after working on some other repository hence with this command you can stage your file so that it would be accessed later on.
For this run:
              git stash ( after git add name of the file )
If you want to save your stash file with a message then run:
              git stash save "a message"
For accessing the file again, use:
              git stash pop / git stash apply the first few characters of commit hash
Commit hash is nothing but a unique ID associated with the commit.
Run git stash list / git stash show for viewing the files in the staging area.


************
13. Git log
This command is used for checking the history of commits.
Run git log --oneline for checking all the commits.
Run git log --before="date" for accessing the commits before a specific date (format of date would be shown by running git log --oneline).
Run git log --after="date" for after that specific date.
Run git log --author="name of the author" for accessing the commits from a particular author.

************
14. Git rebase
Run git rebase branch name this command to ensure that whatever you are working and modifying would store somewhere else so that you can again access it.


************
15. Git config
Well this command is to configure the user's information like it's name and email.
The format goes :

Run git config --list --show-origin for viewing your settings.
Run git config --global user.name " Your name " for changing your name.
Run git config --global user.email " emailid@gmail.com " for changing your e-mail.


************
16. Git remote set-url
This command is used for setting the remote repository.
Run git remote set-url origin name of the repository/git remote add origin name of the repository
************
17. Git merge
This command is used for merging the other branch into the current branch.
Run git merge branch name
************
18. Git revert
This command is to revert to the previous changes.
Run git revert the first few characters of commit hash (which is already explained above)
If you want to revert the changes made in the file back after reverting, then run:
        git revert HEAD

************
19. Git reset
This command is to reset the committed changes back.
Run git reset --hard HEAD for going back to previous commits before HEAD by deleting the un-committed changes.
Run git reset --soft HEAD for going back to previous commits without touching the staged files.
************
20. Git fetch
This command is used for downloading the commits and all the files from the remote repository.
The command goes like:
      git fetch remote-repository-url
************
21. Git diff
This command is used for checking the differences which are not yet staged.

************
22. Git rm
This command is used for deleting any file/folder in the working directory.
The command goes like:
      git rm name of the file/folder


Are you getting bored with online lectures?

Watch this - When online lectures are boring

Watch this for FUN - Funny job interview                               
<><><><><><><><><>
Hope you have learned 
something new
today.
Visit other posts by clicking 
on LABELS for 
learning 
more.
<><><><><><><><><>
Please do follow
and comment 
and don't 
forget 
to 
SUBSCRIBE.
<><><><><><><><><>

Comments

Post a Comment

Popular posts from this blog

How to make your header file in C?-Important topics in C-computer science/Information technology

Making your header file ->Watch this for FUN -  Funny job interview Are you getting bored with online lectures? ->Watch this -  When online lectures are boring   Yes, you can make your header file, as we use the standard header files which are stored in your system, the same way we can also make our. So, let's see how? Step 1 . Define the functions which you will gonna use in the program in some file named (hello.h). Step 2 . In the program file, use #include"hello.h" for including that header file which has been saved by you. <><><><><><><> That's it, you are done, now you can use the functions which you have declared in the hello.h file anywhere in the program. Watch this for FUN -  Funny job interview Are you getting bored with online lectures? Watch this -  When online lectures are boring <><><><><><><> I hope you  have  learned something today. Visit other posts by  clicking

Advanced File handling operations in C-Important topics in C-computer science/Information technology

File handling in C ->Watch this for FUN -  Funny job interview Are you getting bored with online lectures? ->Watch this -  When online lectures are boring   H ere in this blog, we are going to learn how to handle any file on the Computer using this file handling in the C programming language tutorial. So, what's File handling in C?. So, Let's get started with this. File handling in C is an important concept in C programming language which is itself the mother language of all the high-level programming language. Through mastering this, you can master any file in your Personal computer with its content by writing, appending, and doing much more what you can. A file represents a sequence of bytes on the disk where a group of related data is stored in the memory. The file is created for the permanent storage of data.  It is a readymade structure.  In C language, we use a structure pointer of the file type to declare a file which is [FILE *fp] (where fp is the

Standard header files in C programming language-Important topics in C-computer science/Information technology

Standard header files in C programming language ->Watch this for FUN -  Funny job interview Are you getting bored with online lectures? ->Watch this -  When online lectures are boring   Header files are the files that contain the set of predefined library functions that can be used anywhere while writing the program. That's why they become handy in use for their operations while writing a C program. Even you can make your header file. The following header files are the standard ones: 1. stdio.h                This header file is used for various input/output functions like printf() , scanf() ,etc. <><><><><><><> 2. stdlib.h                This header file is mainly used for dynamic memory allocation like malloc() , calloc() , realloc() , free() and even for some functions like abs() [for absolute value of the number] and atoi() [ for converting string to a number] and even more. <><><><><><><&g

What is the general form of a C program in C programming?-Computer Science-Important topic in C

General form  ->Watch this for FUN -  Funny job interview Are you getting bored with online lectures? ->Watch this -  When online lectures are boring   Generally, the C program starts with the header files , followed by preprocessor directives (like macros), and then followed by the functions or the variables to be declared globally which is again followed by the main function for starting the execution. #include<stdio.h> // Header files #define a 10 // Preprocessor directives int x=10; // Global variable int main() // main function { }

Beginning with Computer science??-computer science/Information technology

Are you a beginner in Computer Science? ->Watch this for FUN -  Funny job interview Are you getting bored with online lectures? ->Watch this -  When online lectures are boring   No worries!! Computer Science-Is it a NO or a YES? What do you think? let’s find out! Computer science is the study of computation and information. Computer science has impacted a lot in our daily lives, whether we have to design software or to book something online for shopping. Computer Science Computer science is the medium of all the online services that are evolving throughout the world. So, now you wanna ask me what is computer science build of? Computer science is not just about the front-end that you see in your daily lives but it is built on tonnes and tonnes of codes which run and execute in the back-end part which is not seen-able. Those parts of the code consist of languages generally called programming languages (generally because HTML, CSS are not programming languages). Now you need to know

Functions in C-Computer Science-Important topic in C

 Function in C ->Watch this for FUN -  Funny job interview Are you getting bored with online lectures? ->Watch this -  When online lectures are boring   Function in C is a very important topic in C. The library in C has many in-built functions like printf, scanf, etc. Every C program has at least one main function where the code starts executing.  The main function is declared using int main(). Now, we'll be going to see various types of function declaration, their return types, etc. There are three main things for executing a function in C programming language which are its declaration , its calling , and its execution . The return type of function includes primitive and derived data types. For data types, refer to  this. Function declaration :          There are two ways where you can declare/call a function. Way 1 : Declaring outside the main, globally, int(return type) fun(data type of arguments); For example, void fun(int, char); // Function declaration int main() {  int

Call by value and call by reference in C-Important topics in C-computer science/Information technology

Call by value and Call by Reference  in C ->Watch this for FUN -  Funny job interview Are you getting bored with online lectures? ->Watch this -  When online lectures are boring   There are two ways to call out a function in C and those are Call by Value and Call by Reference. So, what they are, let's find out. <><><><><><><> Call by value :                                 Here the values in the function get copies of the original values but they don't get a revert to the modified value.  For example:                      void swap(int x, int y)                      {                             int temp=x;                             x=y;                             y=temp;                      }                      int main()                     {                      int a=5,b=7;                      swap(a,b);                      printf("%d %d\n",a,b);// Would print 5 7 although the values got modified in the funct

Data types in C-Computer Science-Important topics

 Data Types in C ->Watch this for FUN -  Funny job interview Are you getting bored with online lectures? ->Watch this -  When online lectures are boring   Data types are the building blocks of any programming language. It is the most important topic in C, without data types there couldn't be any foundation of C programming language. So, now let's move on to the types of Data types in C. <><><><><><><> There are three types of data types in C: 1) Primitive data types. 2) Derived data types. 3) User-defined data types. So, let's explore what each one is about: 1) Primitive Data Types Primitive data types in C programming language includes  int, char, float, void . The int data type is used for the declaration of integer variables like: int x=10; // integer x takes value 10 The char data type is used for the declaration of character variables like: char x='a'; // character x takes value a The char data type is used for th

Structures in C programming language-Important topics in C-computer science/Information technology

S tructures in C programming language ->Watch this for FUN -  Funny job interview Are you getting bored with online lectures? ->Watch this -  When online lectures are boring   Structures in C is a very important topic in the C programming language as it can store multiple data types due to which it comes under the user-defined data type.  By the multiple data types, I mean that it can store data types like int, float, char, double, etc. The declaration of a structure in C goes like : struct name{ // name is Name of the structure int n,m; //int data type float f;  //float data type char a[20000];  //character data type }; NOTE :- You cannot initialize any data type in structures , like struct name{ int n=3,m=2; // ERROR float f=3.5; //ERROR }; By using structures, it would become very easy to store multiple information of any kind. For using structures in the int main in C, let's take the example of storing the ID, NAME of the student, the program goes like, #include<stdio.

Vectors in C++-Important topics in C++-Computer science

  Vectors in C++ ->Watch this for FUN -  Funny job interview Are you getting bored with online lectures? ->Watch this -  When online lectures are boring   Vectors in C++ are a sequence container class that implements the dynamic size of the array to store things without caring for its size. ****** Array vs Vectors An array although is a static allocation where size is fixed, but in Vectors, the size is not fixed due to its dynamic nature.  ***** Declaration of Vectors std:: vector<int> vec; //under #include<vector> library ***** Important functions of vectors are: emplace() ->vec.emplace(position,value) inserts the value at the specified position. emplace_back() ->vec.emplace_back(value) inserts the value at the end of the vector. insert() ->vec.insert(position,value) inserts the value at the front of the position given in the function. resize() ->vec.resize(value), resizes the vector's size to the value. reserve() ->vec.reserve(value) reserves the

Translate