Basic Commands of Git

Basic Commands of Git

  • What is Git? Distributed version controlling system for tracking changes in computer files and coordinating work on those files among multiple people; A software;
  • What is Github? Code hosting platform;
  • Learning professional programming Git version control;
  • bitbucket is free for code hosting;
  • Git GNU is based on Git bash; * Commands on Git *
  • The git status command is used to display the state of the repository and staging area. It allows us to see the tracked, untracked files and changes. This command will not show any commit records or information. Mostly, it is used to display the state between Git Add and Git commit command: git status
  • To check the version of git:
    git --version;
    
  • To initialize a git repository:
    git init;
     // If a repository is     initialized then .git(hidden     folder) is     created.
    
  • To uninitialize any repo:
    rm -rf .git
    
  • To make a repository safe or working with pen-drive or external memory:
    git config --global --add safe.directory 'Full File     Location'
    
  • git working flow:
    1.Working Directory 
    2.Staging Area:
    3.Git Directory(Repository)
    
    First of all you need to stage the working files and then you need to commit to save the file;
  • Why the files are not directly saved to the repository? Ans:

  • In order to stage all the files in a folder:

    git add -A
    git add . #stages new and modified, without deleted
    git add -u #stages modified and     deleted, without new
    
  • To commit files in the repository:

    git commit -m "(message you need to give known as commit message)"
    
  • To see who, in which time and the commit changes have been done:

    git log
    
  • To see what is the exact change have been done:

    git diff file_name;
    
  • To see all the changes universally of all the file in the repository:

    git diff;
    
  • To see the change of any staged file:

    git diff --staged file_name;
    
     # It can't be seen by git     diff command as it has been     taken to the staged area;
    
  • To change/set the username for every repository:

    git config --global user.name "Labib Ibn Muzahid"    
    

    If you want to change user and mail for just this repository then don't add --global;

  • To change the email for every repo:
    git config --global user.email     "labibibn8945@gmail.com"
    
  • Public repository is free in github but private is not free;
  • How to write commit message?
    A commit message is that message that is written inside the quotes of the command and this is usually     understandable by human beings, not by the computer;
    

Origin setup in git ;

  • What is origin? An origin is a place where I can push the code or pull the code during worktime; it can be an online code hosting platform like: github, gitlab or bitbucket;
  • To setup an origin:

    git remote add origin origin_name
    
  • What is SSH? a SSH key is pairer between the computer and the github repository.

  • Steps of adding SSH key to the local and online repository;

  • To pull the code from the origin:

    git pull origin master
    
  • To push the code in the origin:
    git push -u origin master  
    
  • To unstage any file:
    git reset file_name;
    
  • To unstage all the files:
    git reset .    
    
  • To reset any file before comitting(storing) and staging:

    git checkout file_name;
    
  • To reset all the file before the 2 layers:

    git checkout .
    
  • All the contents in the directory are listed:
    ls -la;
    
  • To create a blank file:
    touch .gitignore;
    
  • .pyc is known as compiled python code
  • The files we want to track during doing projects like, apart from this files some files are needed to be ignored, those are known as gitignore;
  • To write gitignore files:
    notepad .gitignore;
    

    Branching in Git :

    Why Branch?
  • If you want to work on different files then you must use branch. Suppose you've got a boss saying test a code or you have a very serious project, so on that time you must create another branch and then work on that branch then if you have done any mistakes then you must repent on that, so before repenting creating a casual branch and then practising on that and then pushing it to the main repository or master branch can be a great option for a developer;
  • To create a branch:
    git branch branch_name;
    
  • To return to the master branch:
    git checkout master;
    
  • To take all the changes done in another repository;
    git merge casual_branch_name;
    
  • Deleting the previous branch from lcoal repository:
    git branch -d casual_branch_name
    
  • Deleting the previous branch from remote repository:
    git push origin --delete     casual_branch_name
    
  • Study about the fork and pull request :--This willl be written some other day,,

If you enjoyed reading then please comment as it helps me to create more things for thyself as well as for you guys