Skip to main content

Git Commands

Question: Configure Git

  Answer:  git config --global user.name "Your Name"

   git config --global user.email "your.email@example.com"


Question: Create a new Git repository

  Answer:  git init


Question: Clone a remote repository to your local machine

  Answer:  git clone <repository_url>


Question: Check the status of your working directory and staging area

Answer:  git status



Question: Add changes to the staging area

Answer:  git add <file_name>  # To stage a specific file

   git add .            # To stage all changes



Question: Commit changes to the repository with a descriptive message

Answer: git commit -m "Your commit message here"



Question: Push changes to a remote repository

Answer: 

   git push origin <branch_name>



Question: Pull changes from a remote repository

Answer: 

   git pull origin <branch_name>


Question: Create a new branch

Answer: 

   git branch <branch_name>


Question: Switch to an existing branch

 Answer: 

    git checkout <branch_name>

 

Question: Create a new branch and switch to it in one command

 Answer: 

    git checkout -b <branch_name>

 

Question: Merge changes from one branch to another

 Answer: 

    git merge <source_branch>

 

Question: View the commit history

 Answer: 

    git log

 

Question: View the difference between the working directory and the last commit

 Answer: 

    git diff

 


Question: View the difference between two branches

 Answer: 

    git diff <branch_name> <another_branch_name>

 


Question: Discard changes in the working directory

Answer:  

    git checkout -- <file_name>

 


Question: Discard changes in the staging area and working directory

 Answer: 

    git reset --hard HEAD

 


Question: Undo the last commit and move changes to the staging area

 Answer: 

    git reset --soft HEAD~1

 


Question: Create and apply a stash to save and temporarily remove changes

 Answer: 

    git stash save "Your stash message"

    git stash apply

 


Question: Fetch changes from a remote repository without merging

 Answer: 

    git fetch

 


Question: Rename a file and stage the change

 Answer: 

    git mv <old_file_name> <new_file_name>

 


Question: Delete a branch

Answer:  

    git branch -d <branch_name>

 


Question: Show the remote repositories

 Answer: 

    git remote -v

 


Question: Add a remote repository

 Answer: 

    git remote add <remote_name> <repository_url>

 


Question: Change the remote repository URL

 Answer: 

    git remote set-url <remote_name> <new_repository_url>

 


Question: Push to a specific branch on the remote repository

 Answer: 

    git push <remote_name> <local_branch_name>:<remote_branch_name>

 


Question: Pull changes from a remote repository and automatically merge

 Answer: 

    git pull

 


Question: Create an annotated tag for a specific commit

  Answer: 

    git tag -a <tag_name> -m "Tag message" <commit_sha>

 


Question: List all tags in the repository

  Answer: 

    git tag

 


Question: Show the details of a specific tag

 Answer:  

    git show <tag_name>

 


Question: Revert changes from a specific commit

 Answer:  

    git revert <commit_sha>

 


Question: Change the last commit message

 Answer:  

    git commit --amend -m "New commit message"

 


Question: Move the HEAD to a specific commit

 Answer:  

    git reset <commit_sha>

 


Question: Create a new branch from a specific commit

 Answer:  

    git branch <new_branch_name> <commit_sha>

 


Question: List all branches (local and remote)

 Answer:  

    git branch -a

 


Question: Show the difference between two commits

 Answer:  

    git diff <commit_sha_1> <commit_sha_2>

 


Question: Show a summary of the changes introduced by a commit

 Answer:  

    git show <commit_sha>

 


Question: Move changes from the working directory to the staging area

 Answer:  

    git add -u

 


Question: Delete a file from the working directory and stage the change

 Answer:  

    git rm <file_name>

 


Question: Create an empty commit (useful for triggering hooks)

 Answer:  

    git commit --allow-empty -m "Empty commit"

 


Question: Show the configuration settings

 Answer:  

    git config --list

 


Question: Edit the Git configuration file

 Answer: 

    git config --global --edit

 


Question: Show the Git version

  Answer: 

    git --version

 


Question: Show the working tree status in short format

  Answer: 

    git status -s

 


Question: Show the branch name you are currently on

  Answer: 

    git rev-parse --abbrev-ref HEAD

 


Question: Show the changes made in the last commit

  Answer: 

    git show HEAD

 


Question: Rename a branch

  Answer: 

    git branch -m <old_branch_name> <new_branch_name>

 


Question: Remove files from the staging area but keep the changes in the working directory

  Answer: 

    git reset <file_name>

 


Question: Remove files from the staging area and the working directory

  Answer: 

    git rm --cached <file_name>

 


Question: Undo the last commit and keep the changes in the working directory

  Answer: 

    git reset HEAD~1


Question: How to Resolve Merge Conflicts in Git

 Answer: 


Step 1: The easiest way to resolve a conflicted file is to open it and make any necessary changes.


Step 2: After editing the file, we can use the git add a command to stage the new merged content.


Step 3: The final step is to create a new commit with the help of the git commit command.


Step 4: Git will create a new merge commit to finalize the merge.


Git Commands to Resolve Conflicts

1. git log --merge 

The git log --merge command helps to produce the list of commits that are causing the conflict.


2. git diff 

The git diff command helps to identify the differences between the states repositories or files.


3. git checkout 

The git checkout command is used to undo the changes made to the file, or for changing branches.


4. git reset --mixed 

The git reset --mixed command is used to undo changes to the working directory and staging area.


5. git merge --abort

The git merge --abort command helps in exiting the merge process and returning back to the state before the merging began.


6. git reset

The git reset command is used at the time of merge conflict to reset the conflicted files to their original state.

 


Comments

popular

Privacy policy for Sri Bhagavat Gita

 Privacy Policy for Sri Bhagavad Gita This respects the privacy of its users and is committed to protecting their personal information. This privacy policy outlines the information collected by This and how it is used. Information We Collect : We are not collecting any personal information such as name and email address. This may collect non-personal information such as device type, operating system version, and app usage data to improve the app's functionality and user experience. Sharing of Information This does not sell or share personal information with third parties for marketing purposes. This may share personal information with service providers for the purpose of providing registration or support services to the user. Security of Information This takes reasonable measures to protect user data against unauthorized access, alteration, or destruction. However, This cannot guarantee the security of user data transmitted over the internet. Children's Privacy This does not kn

Privacy policy for BMI calculator

Privacy Policy for BMI Calculator  Effective Date: 5th July 2023 1.1 Personal Information: We do not collect any personally identifiable information (PII) such as your name, address, email, or phone number when you use the App. 1.2 Non-Personal Information: The App may collect certain non-personal information automatically, such as your device's unique identifier (UDID), device type, operating system, language preferences, and anonymous usage statistics. This information is collected to improve the functionality and user experience of the App and is not linked to any personally identifiable information. 2. Use of Information: 2.1 Personal Information: As stated earlier, we do not collect any personal information through the App. Therefore, we do not use or share any personal information. 2.2 Non-Personal Information: The non-personal information collected by the App may be used for the following purposes: - To improve the performance, functionality, and user experience of the App.

privacy policy for Selenium App

 Effective Date: 16 Sep 2023 URL -  https://play.google.com/store/apps/details?id=com.csj.selenium 1. Introduction :   This Privacy Policy outlines how we collect, use, disclose, and safeguard your personal information when you use our Android application ("App"). By accessing or using the App, you agree to the terms and practices described in this Privacy Policy. If you do not agree with our policies and practices, please do not use the App. 2. Information We Collect : - 2.1. Personal Information: We do not collect any personal information from you directly. However, we may collect non-personal information such as device information (e.g., device type, operating system, unique device identifier), and usage data (e.g., pages visited, interactions within the App). 2.2. User-Generated Content: The App allows you to submit questions and answers. Any content you submit will be stored on your local device.  3. How We Use Your Information -We may use non-personal information for an