Github Flashcards
Intro to Git and Github
What is Git and why is it important?
Git is a distributed version control system (VCS) that helps developers track changes to their code and collaborate efficiently without overwriting each other’s work. It is crucial for productivity and code management in software development.
What is a Git repository (repo)?
A repository (repo) is a storage location for your project. It tracks all files and changes made to those files over time, allowing version control and collaboration.
What is a commit in Git?
A commit is a snapshot of your project at a specific point in time. It allows you to track the history of your project and revert to previous states if necessary.
What is the purpose of a branch in Git?
A branch in Git is a copy of your project that allows you to work on changes without affecting the main codebase. You can merge the branch back into the main project when you’re ready.
How do you resolve conflicts during a merge in Git?
Conflicts occur when two branches modify the same part of a file. You need to manually resolve the conflict by choosing which changes to keep and then committing the resolved version.
What is a good commit message?
A good commit message is clear, concise, and describes the purpose of the changes. It should follow a structured format, like Angular-style, with headers such as feat, fix, docs, and so on. For example, feat(user-auth): add OAuth2 login support.
How do you add changes in Git?
Use git add .
to stage all modified files for commit. This prepares the changes to be committed.
What is the difference between git merge
and git rebase
?
Merge: Combines changes from one branch into another, creating a merge commit.
Rebase: Moves the entire feature branch to the tip of the main branch, rewriting the project history by creating new commits.
What is GitHub Flow?
GitHub Flow is a simple branching strategy for smaller teams, where the main branch always contains production-ready code. Developers create feature branches, make changes, and then open pull requests for review and merge.
What is GitFlow?
GitFlow is a more complex branching strategy that includes multiple branches, such as feature, release, and hotfix branches, to manage large projects and multiple versions.
What is a pull request in GitHub?
A pull request is a formal request to merge changes from one branch into another. It allows other developers to review the changes before they are integrated into the main codebase.
How do you check for differences between your working directory and the last commit?
Use git status
to check which files are staged, modified, or untracked. To see specific changes, use git diff
.
Why is a .gitignore file important?
A .gitignore file prevents unnecessary or sensitive files (like build artifacts or personal configurations) from being tracked by Git and pushed to the repository, keeping the project clean.
How do you create a new Git repository?
Use git init to initialize a new repository in the current directory.
Why is it important to have a written convention for Git workflows in a team?
A written convention ensures that all team members follow the same practices, avoiding mistakes, confusion, and merge conflicts, while also helping onboard new members more effectively.