Git version control commands notes
A comprehensive set of Git version control commands and concepts ideal for college students studying programming and software development.
Quiz(48 questions)
1. What is the purpose of a branch in Git?
Terms in this Study Set(48)
Basic Git Commands(12)
git init → what does it do?
Initializes a new Git repository in the current directory. Creates a .git subdirectory.
What command adds files to staging?
Use 'git add <file>'. It stages the specified file for the next commit.
git status → what information does it provide?
'git status' shows the current state of the working directory and staging area: - Modified files - Staged files - Untracked files.
Fill in the blank: 'git ___' commits staged changes.
'git commit' commits changes, creating a new snapshot in the repository.
True or False: 'git commit' can only be used after 'git add'.
True. You must stage changes with 'git add' before committing them.
What command shows the commit history?
'git log' displays a list of commits in the current branch, including author and date.
Compare 'git clone' and 'git init'.
'git clone' creates a copy of an existing repository. 'git init' creates a new repository.
What does 'git remote add' do?
It adds a new remote repository. Syntax: 'git remote add <name> <url>'.
Cause → Effect: Running 'git rm <file>'.
Cause: The command is executed. Effect: The file is removed from the working directory and staged for commit.
What command to discard changes?
'git checkout -- <file>' reverts changes in the specified file to the last committed state.
git config → what is its purpose?
Configures Git settings, such as user name and email, for commits.
What does 'git branch' do?
'git branch' lists all local branches in the repository and indicates the current branch with an asterisk.
Branching and Merging(12)
branch → definition
A branch in Git is a pointer to a specific commit. It enables you to work on different versions of a project simultaneously.
True or False: Merging branches creates a new branch.
False. Merging combines the changes from one branch into another, maintaining the original branches.
How to create a new branch?
Use the command: `git branch <branch-name>` to create a new branch in your repository.
Fill in the blank: To switch to a branch, use the command `git __________`.
`checkout`.
Compare merging vs. rebasing.
- Merging creates a new commit. - Rebasing rewrites commit history for a linear progression.
How to merge branches?
Use: `git merge <branch-name>` while on the target branch to incorporate changes from another branch.
What is a fast-forward merge?
A fast-forward merge occurs when the target branch has no new commits since the source branch diverged, allowing a direct update.
True or False: You can’t delete a branch that is currently checked out.
True. You must switch to a different branch before deleting the current one.
Command to delete a branch:
Use: `git branch -d <branch-name>` to delete a specified branch that has been fully merged.
Cause → Effect: Why use branches?
To isolate development work, allowing multiple features, bug fixes, or experiments without affecting the main codebase.
What does `git checkout -b <branch-name>` do?
Creates a new branch and switches to it in one command.
Merge conflicts occur when...
Two branches have changes to the same line of a file and Git cannot automatically decide which change to keep.
Remote Repositories(12)
git clone → purpose?
The git clone command creates a local copy of a remote repository. - Downloads all files - Copies history and branches
What is the command to add a remote repository?
Use the command: git remote add <name> <url> This links your local repository to a remote one.
True or False: git push overwrites remote branches.
False. git push updates the remote branch with local changes, merging them.
What does git fetch do?
It retrieves updates from the remote repository without merging them into the local branch.
Complete the command: git remote ____
The full command is git remote -v, which lists all configured remote repositories.
git pull vs. git fetch
git pull integrates changes from remote into local branch, while git fetch only downloads them.
What is the command to remove a remote?
Use git remote remove <name> to unlink a remote repository from your local repo.
Purpose of git push?
To upload local commits to a remote repository, ensuring shared access for collaborators.
What do you use to rename a remote?
Use the command: git remote rename <old-name> <new-name> to rename an existing remote.
What command shows remote repository details?
The command git remote show <name> provides detailed information about the specified remote.
Cause of merge conflicts?
Merge conflicts occur when two branches have changes to the same line in a file, requiring manual resolution.
git remote prune origin → what does it do?
This command cleans up remote-tracking branches that no longer exist in the remote repository.
Staging and Committing Changes(12)
What command stages changes for the next commit?
The command is `git add <file>`. It prepares the specified file for committing.
True or False: `git add .` stages all changes.
True. It stages all modified and new files in the current directory.
What does `git commit` do?
`git commit` saves staged changes to the repository with a message.
Command to commit with a message?
`git commit -m "Your message here"` commits with the provided message.
Fill in the blank: To unstage a file, use ______.
`git reset <file>` unstages the specified file from the staging area.
Difference between `git add` and `git commit`?
`git add` stages changes, while `git commit` records those changes in the repository history.
What does `git status` show?
`git status` displays the state of the working directory and staging area.
Cause → Effect: What happens when you commit without staging?
The changes won't be saved in the repository. Only staged changes are committed.
Example of staging multiple files?
`git add file1.txt file2.txt` stages both specified files for the next commit.
What does `git commit --amend` do?
`git commit --amend` modifies the last commit, allowing you to add changes or edit the message.
What is the purpose of commit messages?
Commit messages provide context and descriptions for changes, making collaboration clearer.
True or False: You can commit without a message.
False. Git requires a message to describe the commit in the repository.
Questions in this Study Set(48)
1. What is the purpose of a branch in Git?
2. What command would you use to create a local copy of a remote repository?
3. What command initializes a new Git repository in the current directory?
4. Which command is used to stage changes for the next commit?
5. Which command is used to create a new branch?
6. Which command would you use to link your local repository to a remote repository?
7. Which command is used to stage files for the next commit?
8. True or False: The command 'git add .' stages all changes within the current directory.
9. What happens when you merge branches?
10. True or False: The command 'git push' completely replaces the remote branch with the local branch.
11. What information can you get by running 'git status'?
12. What is the effect of running 'git commit' without staging any changes?
13. What is a fast-forward merge?
14. What is the main function of the 'git fetch' command?
15. Fill in the blank: 'git ___' commits the staged changes.
16. What is the correct command to commit changes with a message?
17. Which command would you use to delete a branch?
18. What does the command 'git remote -v' do?
19. True or False: You can use 'git commit' without first running 'git add'.
20. Fill in the blank: To remove a file from the staging area, you would use ______.
21. What does `git checkout -b <branch-name>` accomplish?
22. What is the difference between 'git pull' and 'git fetch'?
23. Which command displays a log of commits in the current branch?
24. Which of the following best describes the difference between 'git add' and 'git commit'?
25. Which of the following statements about merge conflicts is NOT true?
26. What command should you use to unlink a remote repository from your local repository?
27. What is the difference between 'git clone' and 'git init'?
28. What does the command 'git status' display?
29. What is the effect of using branches in Git?
30. What is the primary purpose of the 'git push' command?
31. What does the command 'git remote add' accomplish?
32. What happens if you attempt to commit without providing a commit message?
33. When is it necessary to switch branches before deleting one?
34. How do you rename a remote repository connection?
35. If you run 'git rm <file>', what happens to the file?
36. What is the function of 'git commit --amend'?
37. How does rebasing differ from merging?
38. Which command would provide detailed information about a specified remote repository?
39. What command would you use to discard local changes in a file?
40. When staging multiple files, which command would you use?
41. What command would you use to switch to a branch?
42. What can cause merge conflicts when using Git?
43. What is the purpose of the 'git config' command?
44. Which of the following is NOT a valid way to stage files?
45. If two developers are working on the same file and make conflicting changes, what should they do?
46. What does the command 'git remote prune origin' do?
47. What does the command 'git branch' do?
48. What is the primary purpose of commit messages in Git?
Related Study Sets
Abitur Rekursion
Abitur: Abitur Klassen und Objekte
Was ist ein Algorithmus Schritt für Schritt
if und Schleifen Notizen
Wiederholung: Funktionen
Test: Binärzahlen
Listen Notizen
Schleife Alltag Beispiel Begriffe
Create Your Own Study Set
Upload a PDF, paste your notes, or describe a topic – AI generates flashcards, quizzes and more in seconds.

