Answer:
git config --global user.name "Your Name" git config --global user.email "[your.email@example.com](mailto:your.email@example.com)"Question: Create a new Git repository
Answer:
git initQuestion: Clone a remote repository to your local machine
Answer:
git cloneQuestion: Check the status of your working directory and staging area
Answer:
git statusQuestion: Add changes to the staging area
Answer:
git addQuestion: Commit changes to the repository with a descriptive message# To stage a specific file git add . # To stage all changes
Answer:
git commit -m "Your commit message here"Question: Push changes to a remote repository
Answer:
git push originQuestion: Pull changes from a remote repository
Answer:
git pull originQuestion: Create a new branch
Answer:
git branchQuestion: Switch to an existing branch
Answer:
git checkoutQuestion: Create a new branch and switch to it in one command
Answer:
git checkout -bQuestion: Merge changes from one branch to another
Answer:
git mergeQuestion: View the commit history
Answer:
git logQuestion: View the difference between the working directory and the last commit
Answer:
git diffQuestion: View the difference between two branches
Answer:
git diffQuestion: Discard changes in the working directory
Answer:
git checkout --Question: Discard changes in the staging area and working directory
Answer:
git reset --hard HEADQuestion: Undo the last commit and move changes to the staging area
Answer:
git reset --soft HEAD~1Question: Create and apply a stash to save and temporarily remove changes
Answer:
git stash push -m "Your stash message" git stash applyQuestion: Fetch changes from a remote repository without merging
Answer:
git fetchQuestion: Rename a file and stage the change
Answer:
git mvQuestion: Delete a branch
Answer:
git branch -dQuestion: Show the remote repositories
Answer:
git remote -vQuestion: Add a remote repository
Answer:
git remote addQuestion: Change the remote repository URL
Answer:
git remote set-urlQuestion: Push to a specific branch on the remote repository
Answer:
git pushQuestion: Pull changes from a remote repository and automatically merge:
Answer:
git pullQuestion: Create an annotated tag for a specific commit
Answer:
git tag -aQuestion: List all tags in the repository-m "Tag message"
Answer:
git tagQuestion: Show the details of a specific tag
Answer:
git showQuestion: Revert changes from a specific commit
Answer:
git revertQuestion: Change the last commit message
Answer:
git commit --amend -m "New commit message"Question: Move the HEAD to a specific commit
Answer:
git resetQuestion: Create a new branch from a specific commit
Answer:
git branchQuestion: List all branches (local and remote)
Answer:
git branch -aQuestion: Show the difference between two commits
Answer:
git diffQuestion: Show a summary of the changes introduced by a commit
Answer:
git showQuestion: Move changes from the working directory to the staging area
Answer:
git add -uQuestion: Delete a file from the working directory and stage the change
Answer:
git rmQuestion: Create an empty commit (useful for triggering hooks)
Answer:
git commit --allow-empty -m "Empty commit"Question: Show the configuration settings
Answer:
git config --listQuestion: Edit the Git configuration file
Answer:
git config --global --editQuestion: Show the Git version
Answer:
git --versionQuestion: Show the working tree status in short format
Answer:
git status -sQuestion: Show the branch name you are currently on
Answer:
git rev-parse --abbrev-ref HEADQuestion: Show the changes made in the last commit
Answer:
git show HEADQuestion: Rename a branch
Answer:
git branch -mQuestion: Remove files from the staging area but keep the changes in the working directory
Answer:
git resetQuestion: Remove files from the staging area but keep them in the working directory
Answer:
git rm --cachedQuestion: Undo the last commit and keep the changes in the working directory
Answer:
git reset HEAD~1Question: How to Resolve Merge Conflicts in Git
Answer: Step 1: The easiest way to resolve a conflicted file is to open it and make the necessary changes.
Step 2: After editing the file, use the git add command to stage the resolved content.
Step 3: The final step is to create a new commit with the git commit command.
Step 4: Git creates a merge commit to finalize the merge when a merge requires a merge commit.
Git Commands to Resolve Conflicts:
1. git log --merge
The git log --merge command helps identify commits that are relevant to the merge conflict.
2. git diff
The git diff command helps identify differences between repository states or files.
3. git checkout
The git checkout command can be used to restore changes to files or switch branches.
4. git reset --mixed
The git reset --mixed command resets the staging area while keeping changes in the working directory.
5. git merge --abort
The git merge --abort command exits the merge process and attempts to restore the state before the merge began.
6. git reset
The git reset command can be used during a merge conflict to reset the index and move the current branch to another state, depending on the specified options.
No comments:
Post a Comment