Learn GIT & Terminal: Beginner's Guide to Version Control & Command Line
Tags: webdev, javascript, beginners, programming
Published: 2022-08-17 15:32:00

Welcome to this comprehensive guide for beginners on mastering Git and Terminal. In this article, we will cover basic Git operations, essential Terminal commands, and the most common steps for working with Git. By following this guide, you will gain a solid foundation in version control and command line tools.

### Create a Repository:

1. Initialize a new local repository:
    
    ```
    git init project_name
    ```
    

1. Clone an existing repository:
    
    ```
    git clone github_repo_url
    ```
    

### Observe Repository:

1. List new or modified files not committed:
    
    ```
    git status
    ```

1. Display full change history:
    
    ```
    git log
    ```
    

### Branches:

1. List all local branches:
    
    ```
    git branch
    ```
    

1. List all local and remote branches:
    
    ```
    git branch -a
    ```
    

1. Switch to a specific branch:
    
    ```
    git checkout my_branch
    ```
    

1. Create a new local branch:
    
    ```
    git branch new_branch
    ```
    

1. Delete a local branch:
    
    ```
    git branch -d my_branch
    ```
    

### Making Changes:

1. Stage a file for commit:
    
    ```
    git add file_name
    ```
    

1. Stage all changed files:
    
    ```
    git add .
    ```
    

1. Commit all staged files:
    
    ```
    git commit -m "some comment"
    ```
    

1. Modify the last commit:
    
    ```
    git commit --amend
    ```
    

1. Unstage a file while keeping changes:
    
    ```
    git reset file_name
    ```
    

### Synchronize:

1. Fetch all updates (branches) from the remote repository:
    
    ```
    git fetch --all
    ```
    

1. Update the current branch with remote branch changes:
    
    ```
    git pull origin branch_name
    ```
    

1. Update the remote branch with local changes:
    
    ```
    git push origin branch_name
    ```
    

### Basic Git Workflow:

1. Clone the remote repository:
    
    ```
    git clone remote_repository_url
    ```
    

1. Add all changes:
    
    ```
    git add .
    ```
    

1. Commit changes with a comment:
    
    ```
    git commit -m "comment"
    ```
    

1. Push changes to the remote repository:
    
    ```
    git push origin master
    ```
    

## Terminal Commands:

Various types of terminals include Git Bash, Command Prompt, PowerShell, JavaScript Debug Terminal, and Zsh. Here are some basic commands to help you navigate and work with the terminal:

1. List all items in the home directory:
    
    ```
    ls
    ```
    

1. Display the current directory path:
    
    ```
    pwd
    ```
    

1. Change the current directory:
    
    ```
    cd folder_name/location_name/desktop
    ```
    

1. Clear the terminal screen:
    
    ```
    clear
    ```
    

1. Go back one directory:
    
    ```
    cd ..
    ```
    

1. Access a specific directory:
    
    ```
    cd /users/your_pc_user_name/project
    ```
    

1. Go to the root directory:
    
    ```
    cd /
    ```
    

1. Create a new directory:
    
    ```
    mkdir folder_name
    ```
    

1. Create multiple directories at once:
    
    ```
    mkdir folder1 folder2
    ```
    

1. List directory contents with additional details:
    
    ```
    ls -l
    ```
    

1. Show hidden files:
    
    ```
    ls -a
    ```
1. Create a new file from the command line:
    
    ```
    touch file_name(file.txt/ file.html/file.css/file.js
    ```
    
1. Create multiple files at once:
        
    ```
    touch file.html file.css file.js
    ```
        
    
1. Remove a specific file:
        
    ```
    rm file.css
    ```
        
    
1. Remove an empty folder:
        
     ```
     rmdir folder_name
     ```
        
    
1. Remove a folder with all its contents:
        
     ```
     rm -rf folder_name
     ```
        
    
That's it for this beginner's guide to Git and Terminal. Stay tuned for more articles, and don't forget to follow me on [Twitter](https://twitter.com/avinashvagh) and connect with me on [LinkedIn](https://linkedin.com/in/avinashvagh) for updates. Also, check out my [Medium](https://medium.com/@avinashvagh) Blog for more content.

Checkout my latest Blog: https://dev.to/avinashvagh/ultimate-roadmap-to-become-full-stack-developer-in-2023-4139
    
Quote of the day:
    
"To win, you have to attack." - Light Yagami (Death Note)
    
 Remember to stay fit, keep coding, explore, and enjoy what you do.