Git Commands

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…


This content originally appeared on DEV Community and was authored by Prarthana

Here are 20 commonly used Git commands every beginner should know:

  1. git init: Initializes a new Git repository in your project folder.
   git init
  1. 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"
  1. git clone: Clones an existing repository from a remote source.
   git clone <repository_url>
  1. git status: Shows the current status of the working directory and staging area.
   git status
  1. git add: Adds files or changes to the staging area.
   git add <file_name>
   git add . # Stages all changes
  1. git commit: Saves changes to the local repository.
   git commit -m "Your commit message"
  1. git log: Displays the commit history.
   git log
  1. git branch: Lists, creates, or deletes branches.
   git branch        # Lists branches
   git branch <name> # Creates a branch
  1. git checkout: Switches between branches.
   git checkout <branch_name>
  1. git merge: Merges a specified branch into the current branch.

    git merge <branch_name>
    
  2. git push: Pushes local commits to the remote repository.

    git push origin <branch_name>
    
  3. git pull: Fetches and merges changes from the remote repository.

    git pull origin <branch_name>
    
  4. git fetch: Fetches changes from the remote repository without merging them.

    git fetch origin
    
  5. git diff: Compares file changes.

    git diff
    
  6. 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>
    
  7. git revert: Reverts a specific commit by creating a new commit.

    git revert <commit_hash>
    
  8. git stash: Temporarily saves uncommitted changes.

    git stash
    
  9. git stash pop: Applies the stashed changes and removes them from the stash.

    git stash pop
    
  10. git rm: Removes a file from the working directory and staging area.

    git rm <file_name>
    
  11. 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! 🚀💻


This content originally appeared on DEV Community and was authored by Prarthana


Print Share Comment Cite Upload Translate Updates
APA

Prarthana | Sciencx (2025-03-08T16:37:51+00:00) Git Commands. Retrieved from https://www.scien.cx/2025/03/08/git-commands-4/

MLA
" » Git Commands." Prarthana | Sciencx - Saturday March 8, 2025, https://www.scien.cx/2025/03/08/git-commands-4/
HARVARD
Prarthana | Sciencx Saturday March 8, 2025 » Git Commands., viewed ,<https://www.scien.cx/2025/03/08/git-commands-4/>
VANCOUVER
Prarthana | Sciencx - » Git Commands. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/03/08/git-commands-4/
CHICAGO
" » Git Commands." Prarthana | Sciencx - Accessed . https://www.scien.cx/2025/03/08/git-commands-4/
IEEE
" » Git Commands." Prarthana | Sciencx [Online]. Available: https://www.scien.cx/2025/03/08/git-commands-4/. [Accessed: ]
rf:citation
» Git Commands | Prarthana | Sciencx | https://www.scien.cx/2025/03/08/git-commands-4/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.