Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions question1.txt
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions question2.txt
Original file line number Diff line number Diff line change
@@ -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 <file-name>
ii) git restore --staged .
iii) git reset HEAD

all the above mentioned commands move changes back to the working directory.

16 changes: 16 additions & 0 deletions question3.txt
Original file line number Diff line number Diff line change
@@ -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.

11 changes: 11 additions & 0 deletions question4.txt
Original file line number Diff line number Diff line change
@@ -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).
10 changes: 10 additions & 0 deletions question5.txt
Original file line number Diff line number Diff line change
@@ -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.
21 changes: 21 additions & 0 deletions question6.txt
Original file line number Diff line number Diff line change
@@ -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.