Skip to the content.

Basic Git Commands 🖥️🖥️🖥️

In this module, we will learn about most used Git commands to get us basic knowledge to make our first contribution to source code.

The Commands 🖥️

  1. git help This command list every possible commands that can be done along with different options that are availabe on Git.
        git help
    
  2. git help tutorial This command opens a documentations about git commands and in-depth explanations of how they all work together.
        git help tutorial
    
  3. git help <command> This command opens documentation for the single command passed in to it as an arguments.
        git help init
    
  4. This is to get and set repository or global options
    ```bash
        git config
    

    Quick notice : This requires the options like (–local, –global)

  5. git init This command creates an empty Git repository - basically a .git directory with subdirectories for objects, refs/heads, refs/tags, and template files
        git init
    

Quick notice: Ensure you are in the right directory/folder of your project before running this command.

  1. git status This display the working tree status. It gives information about the changes and the state of the trackers.
        git status
    
  2. git add This command adds file contents to the index(staging). This is the temporary addition of the contents into the staging environment.This command updates the index using the current content found in the working tree, to prepare the content staged for the next commit. a. Add everything in the directory
        git add .
    

    b. Add a single or multiple individual files

        git add file1 file2
    

    c. To add all

        git add -A
    
  3. git commit This record changes permanently to the repository.
        git commit -m <message>
    
  4. git log This is show commit logs. List commits that are reachable by following the parent links from the given commit(s), but exclude commits that are reachable from the one(s) given with a ^ in front of them. The output is given in reverse chronological order by default.
        git log
    
  5. git push This is to update remote refs along with associated objects. It is updates remote refs using local refs, while sending objects necessary to complete the given refs. bash git push

  6. git remote This manage set of tracked repositories. Manage the set of repositories (“remotes”) whose branches you track. With no arguments, shows a list of existing remotes. Several subcommands are available to perform operations on the remotes.
        git remote
    

Important Options: |- git remote add [-t ] [-m ] [-f] [--[no-]tags] [--mirror=(fetch|push)] |- ``git remote rename`` |- ``git remote remove``

  1. git clone This clones a repository into a newly created directory, creates remote-tracking branches for each branch in the cloned repository (visible using git branch –remotes), and creates and checks out an initial branch that is forked from the cloned repository’s currently active branch.
        git clone
    
  2. git branch This is to list, create, or delete branches

        git branch
    
  3. git checkout This is to switch branches or restore working tree files
        git checkout
    

    Pro tips: the branch as option

  4. git merge This is used to join two or more development histories/branches together. Incorporates changes from the named commits (since the time their histories diverged from the current branch) into the current branch. This command is used by git pull to incorporate changes from another repository and can be used by hand to merge changes from one branch into another.
        git merge
    

Pro tips: .gitignore is a file that contain what is mearnt to not be tracking by git

Exercise

« Previous Module<============================>Next Module »