Git is a distributed version control system (DVCS) that tracks file changes and coordinates work on software development projects. It is an essential tool for collaborative software development and helps developers manage code, collaborate with others, and track changes over time.

Git operates on a distributed model, meaning that each developer has a complete copy of the entire project’s history on their local machine. The distributed nature of Git enables developers to work offline, commit changes, and collaborate seamlessly with others. Git also provides a centralized repository, often hosted on platforms like GitHub, GitLab, or Bitbucket, where developers can share their code, collaborate, and review changes.

Here’s a table of basic Git commands:

Command Description
Getting Started
git initInitialize a new Git repository.
git clone <repository_url>Clone an existing repository.
Basic Commands
git statusCheck the status of your repository.
git add <file>Add changes to the staging area (index).
git add .Add all changes to the staging area.
git commit -m "Your commit message here"Commit changes with a message.
git reset <file>Remove files from the staging area.
git resetUnstage all files from the staging area.
Branching and Merging
git branch <branch_name>Create a new branch.
git checkout <branch_name>Switch to a different branch.
git checkout -b <branch_name>Create and switch to a new branch in one command.
git merge <branch_name>Merge changes from one branch into the current branch.
git branch -d <branch_name>Delete a branch (only if it’s merged).
git branch -D <branch_name>Force delete a branch (use with caution).
Remote Repositories
git remote add <remote_name> <remote_url>Add a remote repository.
git remote -vList remote repositories.
git fetch <remote_name>Fetch changes from a remote repository.
git pull <remote_name> <branch_name>Pull changes from a remote repository into the current branch.
git push <remote_name> <branch_name>Push changes to a remote repository.
git push -u <remote_name> <branch_name>Push changes to a remote repository and set the upstream branch.
Conflict Resolution
git statusCheck for conflicts after a merge or pull.
Manually resolve conflicts in affected files
Add resolved files to the staging area
Commit the resolved changes
Log and History
git logView commit history.
git show <commit_hash>View a specific commit.
git log --onelineShow a concise log with one-line commit messages.
git diff <commit1> <commit2>Show the difference between two commits.
git diffShow the difference between working directory and last commit.
Stashing Changes
git stash save "Your stash message"Save changes to a temporary stash.
git stash listList stashes.
git stash applyApply the latest stash.
git stash apply stash@{n}Apply a specific stash.
git stash drop stash@{n}Delete a stash.
Other Useful Commands
git mv <old_file_name> <new_file_name>Rename a file.
git rm --cached <file>Remove a file from Git (but keep it in the local directory).
git config --listShow Git configuration.
git config --global alias.<alias_name> <git_command>Create an alias for a Git command.
git restore <file>Discard changes in the working directory.