Essential Git Commands for Version Control
Classified in Design and Engineering
Written on in
English with a size of 4.08 KB
Essential Git Commands Reference
Core Repository Management
| COMMAND NAME | USE |
|---|---|
git init | Initialize a local Git repository. |
git add <filename> | Move a particular file to the staging area. |
git add . | Move all files to the staging area. |
git commit -m "commit message" | Create a new commit in Git with a descriptive message. |
git status | Check the status of the current repository and list changed files. |
git log | Show the list of all commits made on a branch. |
git log --oneline | View commit IDs in a brief, one-line format. |
git diff | Show the changes you have made in a file. |
git diff HEAD | Show the difference between the working directory and the last commit. |
git config --global user.name "name" | Set the global Git configuration for the username. |
git config --global user.email "email" | Set the global Git configuration for the email address. |
git push origin <branch_name> | Push the branch to the remote repository. |
git push -d origin <branch_name> | Delete a remote branch in Git. |
git clone <repository_URL> | Copy a Git repository from a remote source. |
git branch <branch_name> | Create a new branch. |
git checkout <branch_name> | Switch from one branch to another. |
git checkout -b <branch_name> | Create and switch to a new branch. |
git branch -d <branch_name> | Delete the specified branch. |
git branch | Show your current branch. |
git merge <branch_name> | Merge one branch into another. |
git rebase | Combine a sequence of commits to a new base commit and maintain a linear project history. |
git stash | Store changes safely in a temporary hidden place. |
git stash list | Show the list of stashed items. |
git stash pop | Bring the stashed files back to the staging area. |
git stash clear | Clear all stashed items. |
git pull | Copy changes from a remote repository to the local repository. |
git fetch | Copy changes into the local Git repository. |
Advanced History and File Operations
| COMMAND NAME | USE |
|---|---|
git revert <commit_ID> | Revert changes from a specific commit. |
git restore --staged <filename> | Reset a staged file. |
git rm <filename> | Remove the file and move the change to the staging area. |
git mv <old_filename> <new_filename> | Change the filename and move the change to the staging area. |
git reset --soft <commit_ID> | Move all items back to the staging area while resetting the commit. |
git reset --hard <commit_ID> | Discard all history and changes back to the specified commit. |
git remote -v | Check if the repository is connected to any remote source. |
.gitignore | A text file that specifies which files and folders should be ignored and not tracked by version control. |