DEV Community

Cover image for Learn GIT & Terminal: Beginner's Guide to Version Control & Command Line
Avinash Vagh
Avinash Vagh

Posted on • Updated on

Learn GIT & Terminal: Beginner's Guide to Version Control & Command Line

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
    
  2. Clone an existing repository:

    git clone github_repo_url
    

Observe Repository:

  1. List new or modified files not committed:

    git status
    
  2. Display full change history:

    git log
    

Branches:

  1. List all local branches:

    git branch
    
  2. List all local and remote branches:

    git branch -a
    
  3. Switch to a specific branch:

    git checkout my_branch
    
  4. Create a new local branch:

    git branch new_branch
    
  5. Delete a local branch:

    git branch -d my_branch
    

Making Changes:

  1. Stage a file for commit:

    git add file_name
    
  2. Stage all changed files:

    git add .
    
  3. Commit all staged files:

    git commit -m "some comment"
    
  4. Modify the last commit:

    git commit --amend
    
  5. Unstage a file while keeping changes:

    git reset file_name
    

Synchronize:

  1. Fetch all updates (branches) from the remote repository:

    git fetch --all
    
  2. Update the current branch with remote branch changes:

    git pull origin branch_name
    
  3. 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
    
  2. Add all changes:

    git add .
    
  3. Commit changes with a comment:

    git commit -m "comment"
    
  4. 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
    
  2. Display the current directory path:

    pwd
    
  3. Change the current directory:

    cd folder_name/location_name/desktop
    
  4. Clear the terminal screen:

    clear
    
  5. Go back one directory:

    cd ..
    
  6. Access a specific directory:

    cd /users/your_pc_user_name/project
    
  7. Go to the root directory:

    cd /
    
  8. Create a new directory:

    mkdir folder_name
    
  9. Create multiple directories at once:

    mkdir folder1 folder2
    
  10. List directory contents with additional details:

    ls -l
    
  11. Show hidden files:

    ls -a
    
  12. Create a new file from the command line:

    touch file_name(file.txt/ file.html/file.css/file.js
    
  13. Create multiple files at once:

    touch file.html file.css file.js
    
  14. Remove a specific file:

    rm file.css
    
  15. Remove an empty folder:

     rmdir folder_name
    
  16. 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 and connect with me on LinkedIn for updates. Also, check out my Medium 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.

Top comments (0)