Git Flashcards
What is the git command that downloads any repository from GitHub to your computer?
The git command that downloads any repository from GitHub to your computer is
git clone <repository URL>
What are the 5 steps to push a file from your local system to the GitHub repository using Git?
Initialize Git: git init
Add file to staging area: git add <file>
Commit changes: git commit -m "Commit message"
Add remote repository: git remote add origin <remote repository URL>
Push changes: git push origin master
What is the process for reverting a commit that has already been pushed and made public?
There are two ways that you can revert a commit. What is the first?
- Remove or fix the bad file in a new commit and push it to the remote repository. Then commit it to the remote repository using:
git commit –m "commit message"
What is the process for reverting a commit that has already been pushed and made public?
There are two ways that you can revert a commit. What is the second?
- Use
git log
to find the commit hash of the specific commit you want to revert. - Create a new commit that undoes all the changes that were made in the bad commit with this command:
git revert <commit id> Example: git revert 56de0938f
Explain the difference between Git Fetch and Git Pull.
Git Fetch: Fetches the latest changes from a remote repository to your local repository, but does not merge or modify your local branches.
Git Pull: Fetches the latest changes from a remote repository and automatically merges them into your current branch.
What is branching in Git?
Branching allows developers to work on new features, bug fixes, or experiments without affecting the main codebase until they are ready to be merged.
Pros of branching in Git? 3
Parallel Development
Collaboration and Code Review
Rollback and Versioning
Q: How do you create a new branch?
A: Use the command git branch branch_name
to create a new branch with the given name.
After creating the branch, you can switch to it using the git checkout command: git checkout <branch-name>
Alternatively, you can combine the branch creation and checkout into a single command using the -b flag: git checkout -b <branch-name>
Q: How do you switch to a different branch?
A: Use the command “git checkout branch_name” to switch to the specified branch.
Q: How do you switch to a different branch?
A: Use the command “git checkout branch_name” to switch to the specified branch.
Is Git Merge or Git Rebase better?
It depends on the situation and project requirements.
If preserving the commit history and the order of commits is important, git merge is a better choice.
If you want a cleaner and more linear commit history without unnecessary merge commits, git rebase is preferred.
What scenarios usually require you to use git merge over git rebase and vice versa?
git merge
is generally recommended for shared branches and collaborative projects,
git rebase
is useful for individual feature branches
What are the advantages of Git Merge?
Git Merge preserves the original commit history and allows for easy identification of individual contributions.
What are the advantages of Git Rebase?
Git Rebase creates a clean and linear commit history without the additional merge commits, making it easier to follow changes.
What are the disadvantages of Git Rebase? 2
Rewrites commit history making it challenging for others to synchronize their work.
Risk of losing changes: Accidental loss or overwriting of commits if not performed correctly.