diff --git a/question1.txt b/question1.txt new file mode 100644 index 0000000..9663cb3 --- /dev/null +++ b/question1.txt @@ -0,0 +1,18 @@ +question 1 :- How to set multiple remote repositories for the same project? Explain the use case. you should have a working demo of it. + +answer :- we can configure a project to push and pull from multiple remote repositories. This is useful for: + +i) Backup repositories (e.g., GitHub + GitLab). +ii) Team collaboration across different platforms. +iii) Deploying code to multiple servers. + +command for setting remote repositories is: +i) git remote set-url --add --push origin git@github.com:username/repo.git +ii) git remote set-url --add --push origin git@gitlab.com:username/repo.git + + +working demo of remote repositories:- +--git add . +--git commit -m "first commit" +--git push origin main +--git push gitlab master diff --git a/question2.txt b/question2.txt new file mode 100644 index 0000000..8a851ec --- /dev/null +++ b/question2.txt @@ -0,0 +1,9 @@ +question 2 :- How to un-stage changes from the staged area. write command for it. + +answer :- To un-stage changes (move files from the staged area back to the working directory) in Git, use the following commands: +i) git restore --staged +ii) git restore --staged . +iii) git reset HEAD + +all the above mentioned commands move changes back to the working directory. + diff --git a/question3.txt b/question3.txt new file mode 100644 index 0000000..5d85719 --- /dev/null +++ b/question3.txt @@ -0,0 +1,16 @@ +question 3 :- What happens when a file is deleted in the main branch and updated in a feature branch, and how is this handled during a merge? + +answer :- When a file is deleted in the main branch and modified in a feature branch, Git encounters a conflict during merging because it cannot automatically decide whether to: + +i) Keep the deleted state from main, or +ii) Apply the modifications from the feature branch. + +Resolving the Conflict +i) keep the deleted file +ii) keep the updated file + +key takeaways: +i) git cannot automatically resolve a delete/modify conflict. +ii) we must choose to either keep or delete the file. +iii) After resolving, commit the changes to complete the merge. + diff --git a/question4.txt b/question4.txt new file mode 100644 index 0000000..26ff1c2 --- /dev/null +++ b/question4.txt @@ -0,0 +1,11 @@ +question 4 :- What does the git ls-files command do, and what information does its output provide regarding the state of files in a Git repository? + +answer :- The git ls-files command provides a list of files that are currently being tracked by Git in a repository. It shows the files in the staging area (index) and working directory, helping you understand which files Git is currently aware of. + +command :- git ls-files + +This command outputs the list of tracked files in the repository, which are: + +i) Staged files (those added with git add). +ii) Committed files (files already committed to the repository). +iii) Unmodified files (those unchanged since the last commit). diff --git a/question5.txt b/question5.txt new file mode 100644 index 0000000..906cc82 --- /dev/null +++ b/question5.txt @@ -0,0 +1,10 @@ +question 5 :- Under what conditions will Git consider a file that has been deleted as being renamed, and what criteria does Git use to determine that a new file is a renamed version of the deleted file? + +answer : In Git, renaming a file is a special case. Git doesn’t have a dedicated rename command. Instead, it detects renames through the comparison of file content and the file’s history. When a file is deleted in one commit and modified or added with similar content in another, Git may treat it as a rename. + +Conditions for Git to Recognize a Rename + +i) File content similarity. +ii) File Deletion and Addition on Different Branches. +iii) Not Too Much Change in Content. +iv) File path. diff --git a/question6.txt b/question6.txt new file mode 100644 index 0000000..b1f2180 --- /dev/null +++ b/question6.txt @@ -0,0 +1,21 @@ +question 6 :- Why is it not possible to create two branches with the names fix and fix/bug in a Git repository, and what causes this conflict? + +answer : In Git, the reason you cannot create two branches with the names fix and fix/bug is due to the way Git handles branch naming conventions and file paths. Specifically, Git uses a slash (/) in branch names to denote a hierarchical structure, which can lead to conflicts. + +i) In Git, branch names can have slashes (/) to create a "folder-like" structure. For example, you can have:- + +a) fix (a branch named fix). + +b) fix/bug (a branch named bug under the fix directory, which is logically a sub-branch). + +ii) Git's Internal Directory Structure:- + +Git internally stores branches in the .git/refs/heads/ directory (or a similar structure for remotes). Git treats slashes as a path separator. So, when you create a branch like fix/bug, Git internally sees it as a folder called fix with a file named bug inside it, making it a hierarchical branch name. + +iii) Conflict When Naming fix and fix/bug:- + +a) If you attempt to create a branch named fix, it will be created as a file in .git/refs/heads/fix. + +b) If you try to create a branch named fix/bug, Git will try to create a file in .git/refs/heads/fix/bug, but since fix is already a valid directory (a "folder" for Git), Git cannot create a second branch at fix and fix/bug because it sees the fix branch as an existing directory. + +