Here are 20 commonly used Git commands every beginner should know:
-
git init
: Initializes a new Git repository in your project folder.
git init
-
git config
: Configures user details such as name and email.
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
-
git clone
: Clones an existing repository from a remote source.
git clone <repository_url>
-
git status
: Shows the current status of the working directory and staging area.
git status
-
git add
: Adds files or changes to the staging area.
git add <file_name>
git add . # Stages all changes
-
git commit
: Saves changes to the local repository.
git commit -m "Your commit message"
-
git log
: Displays the commit history.
git log
-
git branch
: Lists, creates, or deletes branches.
git branch # Lists branches
git branch <name> # Creates a branch
-
git checkout
: Switches between branches.
git checkout <branch_name>
-
git merge
: Merges a specified branch into the current branch.
git merge <branch_name>
-
git push
: Pushes local commits to the remote repository.
git push origin <branch_name>
-
git pull
: Fetches and merges changes from the remote repository.
git pull origin <branch_name>
-
git fetch
: Fetches changes from the remote repository without merging them.
git fetch origin
-
git diff
: Compares file changes.
git diff
-
git reset
: Undoes changes in the staging area or moves the HEAD to a previous commit.
git reset <file_name> git reset --hard <commit_hash>
-
git revert
: Reverts a specific commit by creating a new commit.
git revert <commit_hash>
-
git stash
: Temporarily saves uncommitted changes.
git stash
-
git stash pop
: Applies the stashed changes and removes them from the stash.
git stash pop
-
git rm
: Removes a file from the working directory and staging area.
git rm <file_name>
-
git show
: Shows details of a specific commit.
git show <commit_hash>
These commands should give you a solid foundation for managing your projects with Git. Let me know if you'd like further clarification on any of them! ππ»
Top comments (0)