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:
-
Initialize a new local repository:
git init project_name
-
Clone an existing repository:
git clone github_repo_url
Observe Repository:
-
List new or modified files not committed:
git status
-
Display full change history:
git log
Branches:
-
List all local branches:
git branch
-
List all local and remote branches:
git branch -a
-
Switch to a specific branch:
git checkout my_branch
-
Create a new local branch:
git branch new_branch
-
Delete a local branch:
git branch -d my_branch
Making Changes:
-
Stage a file for commit:
git add file_name
-
Stage all changed files:
git add .
-
Commit all staged files:
git commit -m "some comment"
-
Modify the last commit:
git commit --amend
-
Unstage a file while keeping changes:
git reset file_name
Synchronize:
-
Fetch all updates (branches) from the remote repository:
git fetch --all
-
Update the current branch with remote branch changes:
git pull origin branch_name
-
Update the remote branch with local changes:
git push origin branch_name
Basic Git Workflow:
-
Clone the remote repository:
git clone remote_repository_url
-
Add all changes:
git add .
-
Commit changes with a comment:
git commit -m "comment"
-
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:
-
List all items in the home directory:
ls
-
Display the current directory path:
pwd
-
Change the current directory:
cd folder_name/location_name/desktop
-
Clear the terminal screen:
clear
-
Go back one directory:
cd ..
-
Access a specific directory:
cd /users/your_pc_user_name/project
-
Go to the root directory:
cd /
-
Create a new directory:
mkdir folder_name
-
Create multiple directories at once:
mkdir folder1 folder2
-
List directory contents with additional details:
ls -l
-
Show hidden files:
ls -a
-
Create a new file from the command line:
touch file_name(file.txt/ file.html/file.css/file.js
-
Create multiple files at once:
touch file.html file.css file.js
-
Remove a specific file:
rm file.css
-
Remove an empty folder:
rmdir folder_name
-
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)