rohansanghai / git-basic-commands

Most widely used Git basic commands

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Most widely used Git basic commands

Click ⭐ if you like the project. Pull Requests are highly appreciated.

Table of Contents


No. Questions
1 Git: Configuration
2 Git: starting as a repository
3 Git: staging files
4 Git: committing to a repository
5 Git: pulling and pushing from and to repositories
6 Git: branching
  1. Git: Configuration

    Before you start using a git. Git wants you to do registration with git

    To tell Git who you are, run the following two commands:

        $ git config --global user.name "mentionedYourGitUsername"
        $ git config --global user.email "mentionGitRegisterEmailId"

    We are able to see the outputs from many git commands in the terminal. We can have colorful out for the commands what we are running in terminal.

    To turn on code highlighting, just run the following command:

        $ git config --global color.ui true

    The last basic configuration command will let you view your Git configurations. Running this command is the same as asking for a copy of your contract:

        $ git config --list
        user.name=GitUserName
        user.email=GitRegisterdEmailId

    ⬆ Back to Top

  2. Git: starting as a repository

        $ git init

    The "init" command stands for initialize. Once you run "git init", Git will initialize a hidden directory called ".git" in the project's root directory.

    To know the Git status, you'll need to run:

        $ git status

    ⬆ Back to Top

  3. Git: staging files

        $ git add <file-name>
    
        $ git add <file-name> <another-file-name> <yet-another-file-name>
    
        $ git add .
    
        $ git add --all
    
        $ git add -A
    
        $ git add --cached <file-name>
    
        $ git reset <file-name>

    ⬆ Back to Top

  4. Git: committing to a repository

        $ git commit -m "Add Files"
    
        $ git reset --soft HEAD^
    
        $ git commit --amend -m <enter your message>

    ⬆ Back to Top

  5. Git: pulling and pushing from and to repositories

        $ git remote add origin <link>
    
        $ git push -u origin master
    
        $ git add <file-name>
    
        $ git clone <clone URL>
    
        $ git pull

    ⬆ Back to Top

  6. Git: branching

        $ git branch
    
        $ git branch <branch-name>
    
        $ git checkout <branch-name>
    
        $ git merge <branch-name>
    
        $ git checkout -b <branch-name>

    ⬆ Back to Top

  7. Git:

        $ git diff <file-name>
    
        $ git checkout <file-name> undo changes made in file
    
        $ git stash - remove all changes
    
        $ git clean -fx - remove untracked files
    
        $ git log - 
    
        $ git log --all -- Display All Commits
    
        $ git log -3 -- View most recent commits

    Filter Commits By Author or Committer

        $ git log --author <name>
        $ git log --committer <name>

    View All Diff of Changes for Each Commit

        $ git log -p

    View Summary of Changes for Each Commit

        $ git log --stat

    Help

        $ git help