Basic Git commands

Git is a distributed version control system used for tracking changes in files and is a fast process.Where we link our local repository and Github repository write code and commit into Github repo.

  1. To Initialize a git repository:

     ubuntu@ip-172-31-2-75:~/dir3$ git init
     hint: Using 'master' as the name for the initial branch. This default branch name
     hint: is subject to change. To configure the initial branch name to use in all
     hint: of your new repositories, which will suppress this warning, call:
     hint:
     hint:     git config --global init.defaultBranch <name>
     hint:
     hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
     hint: 'development'. The just-created branch can be renamed via this command:
     hint:
     hint:     git branch -m <name>
     Initialized empty Git repository in /home/ubuntu/dir3/.git/
    
  2. To link local and GitHub repo:

     ubuntu@ip-172-31-2-75:~/dir3$ git remote add origin <repository url>
    
  3. To clone GitHub repository URL:

     ubuntu@ip-172-31-2-75:~/dir3$ git clone <URL>
    
  4. To add file to staging area:

     ubuntu@ip-172-31-2-75:~/dir3$ git add .
    
  5. To commit changes from staging area to repository:

  1.  ubuntu@ip-172-31-2-75:~/dir3$ git commit -m "commit message"
    
  1. To check the status of repository:

     ubuntu@ip-172-31-2-75:~/dir3$ git status
    
  2. To push code into GitHub repo:

     ubuntu@ip-172-31-2-75:~/dir3$ git push -u origin master
    
  3. To pull code from GitHub:

     ubuntu@ip-172-31-2-75:~/dir3$ git pull
    
  1. To check who has committed:

     ubuntu@ip-172-31-2-75:~/dir3$ git log
    
  1. to see what code is committed:

     ubuntu@ip-172-31-2-75:~/dir3$ git show