Git Commands and Associated Questions Estimated reading: 3 minutes 16 views What is Git?Answer: Git is a distributed version control system that allows developers to track changes in source code, collaborate on projects, and maintain a full history of the codebase.How do you initialize a Git repository?Answer: To initialize a new Git repository, use: git init How do you clone a remote Git repository?Answer: To clone an existing repository from a remote location, use: git clone How do you check the status of the repository?Answer: To check the status, which shows staged, unstaged, and untracked files, use: git status How do you add changes to the staging area?Answer: To add a specific file: git add To add all changes: git add . How do you commit changes in Git?Answer: To commit changes with a message, use: git commit -m "Your commit message" How do you push local changes to a remote repository?Answer: To push changes to a specific branch on the remote repository: git push origin How do you pull changes from a remote repository?Answer: To fetch and merge changes from the remote repository: git pull origin How do you create a new branch in Git?Answer: To create and switch to a new branch: git checkout -b How do you switch branches in Git?Answer: To switch to an existing branch: git checkout How do you merge branches in Git?Answer: To merge a branch into the currently active branch: git merge How do you delete a local branch in Git?Answer: To delete a local branch: git branch -d How do you delete a remote branch in Git?Answer: To delete a remote branch: git push origin --delete How do you view the commit history?Answer: To view the commit history, use: git log How do you view all branches in the repository?Answer: To list all local branches: git branch To list remote branches: git branch -r How do you revert a commit in Git?Answer: To revert the changes made by a commit, creating a new commit that undoes it: git revert How do you reset your repository to a previous commit?Answer: To reset to a previous commit and discard changes: git reset --hard How do you create a tag in Git?Answer: To create a tag for a commit: git tag How do you push tags to a remote repository?Answer: To push a tag to a remote repository: git push origin How do you view a list of all the tags in the repository?Answer: To list all tags: git tag How do you stash changes in Git?Answer: To temporarily save changes that aren’t ready to be committed: git stash How do you apply stashed changes?Answer: To apply stashed changes: git stash apply How do you drop a stash from the list of stashes?Answer: To remove a specific stash: git stash drop How do you list all the stashes?Answer: To list all stashed changes: git stash list How do you fetch changes from a remote repository without merging them?Answer: To fetch changes without merging: git fetch What is the difference between git pull and git fetch?Answer:git fetch only downloads changes from the remote repository but doesn’t merge them.git pull fetches and merges the changes into the current branch.