Home - Abhijeet120303/SGTek-Internship GitHub Wiki
Second Day Learning Of Internship
Git Interview Questions:
1)How do you create a new branch in Git? Answer: To create a new branch in Git, you use the command git checkout -b . This command creates and switches to the new branch simultaneously.
2)What is a Git branch? Answer: A Git branch is a separate line of development in a Git repository. It allows developers to work on features, bug fixes, or experiments without affecting the main codebase. Branches enable parallel development and can later be merged back into the main branch.
3)Explain the difference between Git branches and tags. Answer: Git branches are pointers to a specific commit, representing a line of development. They are dynamic and can be moved. Tags, on the other hand, are references to specific commits and are typically used to mark important points in history, such as releases. Tags are static and do not change.
4)How do you merge one branch into another in Git? Answer: To merge one branch into another, you use the command git merge . This integrates changes from the specified branch into the current branch.
5)Why is it important to have a consistent branch naming convention? Answer: A consistent branch naming convention improves project organization and communication within a team. It makes it easier to understand the purpose of each branch and helps in tracking features, bug fixes, and releases.
6)How do you delete a Git branch locally? Answer: To delete a Git branch locally, you use the command git branch -d . If the branch contains unmerged changes, you can force delete it using git branch -D .
7)What is Git merge, and how does it work? Answer: Git merge is a command that integrates changes from one branch into another. It creates a new commit that combines the changes from the source branch into the target branch. This process allows for the synchronization of different lines of development.
8)What is the purpose of git merge in Git? Answer: git merge is used to integrate changes from one branch into another. It creates a new commit that combines changes from the source branch into the target branch.
9)What is the purpose of git pull? Answer: git pull is used to fetch changes from a remote repository and merge them into the current branch. It is a combination of git fetch (to fetch changes) and git merge (to integrate those changes).
10)What is the difference between a "pull request" and a "merge" in Git? Answer: A "pull request" is a feature provided by platforms like GitHub or GitLab, where changes made in a branch are proposed for merging into another branch. The "merge" operation, on the other hand, is the actual integration of those proposed changes into the target branch.
Branch Naming Convention :
1)Feature Branches: feature/: For new features or enhancements. Example: feature/user-authentication
2)Bug Fix Branches: bugfix/: For bug fixes. Example: bugfix/123-fix-login-issue
Merge Conflict :-
A merge conflict in Git occurs when there are conflicting changes in different branches that Git is attempting to merge. This conflict arises when Git is unable to automatically reconcile the changes because they affect the same lines in a file or when Git cannot determine which changes to incorporate.
Here's a step-by-step breakdown of how a merge conflict typically happens:
1)Branching: Developers work on separate branches to implement features or fix bugs.
2)Changes in Different Branches: Different developers (or the same developer in different branches) make changes to the same part of a file or files.
3)Merging/Branch Integration: When attempting to merge one branch into another (e.g., using git merge), Git compares the changes made in each branch.
4)Conflict Detection: If Git detects that changes in the branches overlap and cannot be automatically merged, it declares a merge conflict.
5)Conflict Markers: Git marks the conflicting sections in the affected files with special markers (such as <<<<<<<, =======, and >>>>>>>) to indicate the conflicting changes from the source and destination branches.
6)Manual Resolution: The developer needs to manually resolve the conflict by editing the file to choose which changes to keep or by combining the changes.
7)Resolution Commit: After resolving the conflict, the developer needs to commit the changes to complete the merge.