When collaborating on a project, you typically push your changes to the _______ branch of the remote repository.
- master
- main
- origin
- remote
By convention, when collaborating, changes are pushed to the master branch. However, note that some projects may use main as the default branch.
If you have committed the wrong files to Git, what command can you use to undo this last commit?
- git reset --soft HEAD^
- git revert HEAD
- git reset --hard HEAD^
- git reset HEAD^
The correct option, git reset --hard HEAD^, is also used in this scenario to completely undo the last commit along with the changes. It discards the commit and resets the branch pointer. Other options are for different use cases: preserving changes, creating a new commit to undo changes, and unstaging changes.
A development team is experiencing slow performance when working with a Git repository containing large binary files. What Git feature should they consider implementing?
- Git LFS (Large File Storage)
- Shallow clones
- Git submodules
- Git Hooks
The team should consider implementing Git LFS (Large File Storage) to efficiently handle large binary files. Git LFS is designed for versioning large files, preventing performance issues.
What are the implications of adopting a Git workflow in a distributed team with respect to continuous integration?
- CI can become complex due to multiple branches
- CI is not affected by distributed teams
- Distributed teams have no impact on CI
- CI is faster in distributed teams
Git Workflow and CI
To save changes in a new stash, you would use git stash ______.
- save
- create
- push
- store
The command to stash changes is git stash save, which saves the changes in the stash without committing them to the repository. This is useful when you need to switch to a different branch or address an urgent issue.
What is the importance of Git hooks in automating tasks in CI/CD pipelines?
- Code Deployment
- Code Review
- Automated Testing
- Task Automation
Git hooks are scripts triggered by Git events, such as pre-commit or post-merge. They play a vital role in CI/CD pipelines by automating tasks like code testing and deployment, ensuring a seamless development workflow.
You're working on a feature in a separate branch and want to include recent changes from the main branch. What Git strategy should you use?
- Merge
- Rebase
- Cherry-pick
- Reset
When working on a separate branch and wanting to include recent changes from the main branch, the recommended Git strategy is to rebase. Rebasing incorporates changes from one branch into another and results in a cleaner, linear project history. Merging is another option, but it can create unnecessary merge commits. Cherry-pick and reset are not typically used for this scenario.
What is an essential step in ensuring a smooth transition from a centralized VCS to Git?
- Train team members on Git fundamentals and best practices.
- Avoid training and let the team adapt on their own.
- Perform the migration without informing the team to minimize resistance.
- Hire external consultants to handle the transition.
Training team members on Git fundamentals and best practices is essential for a smooth transition. Avoiding training may lead to confusion, and informing and involving the team in the process helps mitigate resistance. Hiring external consultants may not address the internal team's needs effectively.
How can you combine multiple commits into one using Git?
- Use the git merge command with the --squash option to condense multiple commits into one before merging.
- Execute git commit --combine for the commits you want to merge, specifying the commit range.
- Use the git rebase command with the -i (interactive) option to squash, fixup, or reword commits interactively.
- Create a new branch, cherry-pick the desired commits onto it, and then merge the new branch.
Git rebase with the -i option allows for interactive rebasing, including the ability to squash commits together, providing a cleaner history.
During migration to Git, what is the best strategy to preserve the commit history from the previous version control system?
- Create a mapping between old and new commits, ensuring each commit is accounted for.
- Discard the old commit history for simplicity.
- Convert all old commits into a single initial commit in Git.
- Use a third-party tool to import commits directly.
When migrating to Git, it's crucial to establish a mapping between old and new commits to preserve the commit history accurately. Discarding history or converting all commits into one may result in loss of valuable information. Using third-party tools can help in importing commits seamlessly.