DEV Community

Cover image for 👨‍💻Mastering Git: A Beginner’s Guide to the 12 Most Essential Commands🫠
Pratik Tamhane
Pratik Tamhane

Posted on • Updated on

👨‍💻Mastering Git: A Beginner’s Guide to the 12 Most Essential Commands🫠

1. Getting Started with Git: git init

Summary: Learn how to start a new Git project from scratch by initializing a local repository using git init. We’ll cover what this command does, common use cases, and how to structure your initial commits for a clean project history.

Commands:

git init
git add .
git commit -m "Initial commit"

Enter fullscreen mode Exit fullscreen mode

2. Cloning Repositories: git clone

Summary: Dive into the git clone command, the go-to tool for copying remote repositories to your local machine. Understand how to clone repositories from GitHub, GitLab, and other platforms, and learn how to work with different branches during cloning.

Commands:

git clone <repository-url>
cd <repository-name>
Enter fullscreen mode Exit fullscreen mode

3. Monitoring Your Changes: git status

Summary: git status is your go-to command for tracking changes in your working directory. Learn how to use this command effectively to keep your workflow clean and organized, and understand how it relates to staging and committing files.

Commands:

git status

Enter fullscreen mode Exit fullscreen mode

4. Adding Files to Staging: git add

Summary: Discover how to stage files and directories using the git add command. This post will cover the basics, from adding individual files to adding everything with a single command, and common mistakes to avoid.

Commands:

git add <file-name>
git add .

Enter fullscreen mode Exit fullscreen mode

5. Making Commits: git commit

Summary: Explore how to use git commit to create snapshots of your project. Learn the importance of writing clear commit messages, how to use flags like -m and --amend, and how to craft a well-documented commit history.

Commands:

git commit -m "Your commit message"
git commit --amend
Enter fullscreen mode Exit fullscreen mode

6. Pushing Changes: git push

Summary: Uncover the mechanics of git push to upload your local commits to a remote repository. This post will help you understand how to manage branches, remote repositories, and handle push conflicts.

Commands:

git push origin <branch-name>
Enter fullscreen mode Exit fullscreen mode

7. Pulling Updates: git pull

Summary: Learn how to use git pull to download and integrate changes from a remote repository into your local branch. This post will also explain the differences between git pull and git fetch, and how to resolve potential conflicts.

Commands:

git pull origin <branch-name>
Enter fullscreen mode Exit fullscreen mode

8. Managing Branches: git branch

Summary: Discover the power of branching with git branch. We’ll cover how to create, list, rename, and delete branches, and why branches are essential for managing features, bug fixes, and releases in your projects.

Commands:

git branch <new-branch-name>
git branch -d <branch-name>
git branch
Enter fullscreen mode Exit fullscreen mode

9. Switching Branches: git checkout

Summary: Understand how to use git checkout to switch between branches or revert to previous commits. This post will delve into common scenarios, like recovering from mistakes and creating new branches from existing commits.

Commands:

git checkout <branch-name>
git checkout -b <new-branch-name>
Enter fullscreen mode Exit fullscreen mode

10. Merging Changes: git merge

Summary: Learn the ins and outs of git merge, from fast-forward merges to resolving conflicts. This post will explain how to integrate changes from one branch into another smoothly, and how to avoid merge pitfalls.

Commands:

git merge <branch-name>
Enter fullscreen mode Exit fullscreen mode

11. Comparing Changes: git diff

Summary: Dive into git diff to compare changes between commits, branches, or your working directory. Understand how to interpret the output, track changes over time, and incorporate git diff into your daily workflow.

Commands:

git diff
git diff <commit-sha>
Enter fullscreen mode Exit fullscreen mode

12. Viewing History: git log

Summary: Learn how to use git log to explore the history of your repository. We’ll cover common options, such as filtering by author or date, visualizing the commit graph, and customizing the output for better readability.

Commands:

git log
git log --oneline
git log --graph --decorate --all
Enter fullscreen mode Exit fullscreen mode

Happy coding! 🚀

Advance Commands : https://dev.to/uicraft_by_pratik/git-mastery-medium-level-commands-to-elevate-your-workflow-1ijc

LinkedIn : https://www.linkedin.com/in/pratik-tamhane-583023217/

Behance : https://www.behance.net/pratiktamhane

Top comments (2)

Collapse
 
blenderman profile image
BBM

This is a really helpful guide for beginners! Do you plan to cover more advanced Git commands in a future post?

Collapse
 
uicraft_by_pratik profile image
Pratik Tamhane • Edited

yes definitely ❤️ my secound post dev.to/uicraft_by_pratik/git-maste...