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 NAMEUSE
git initInitialize 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 statusCheck the status of the current repository and list changed files.
git logShow the list of all commits made on a branch.
git log --onelineView commit IDs in a brief, one-line format.
git diffShow the changes you have made in a file.
git diff HEADShow 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 branchShow your current branch.
git merge <branch_name>Merge one branch into another.
git rebaseCombine a sequence of commits to a new base commit and maintain a linear project history.
git stashStore changes safely in a temporary hidden place.
git stash listShow the list of stashed items.
git stash popBring the stashed files back to the staging area.
git stash clearClear all stashed items.
git pullCopy changes from a remote repository to the local repository.
git fetchCopy changes into the local Git repository.

Advanced History and File Operations

COMMAND NAMEUSE
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 -vCheck if the repository is connected to any remote source.
.gitignoreA text file that specifies which files and folders should be ignored and not tracked by version control.

Related entries: