Git version control commands notes

A comprehensive set of Git version control commands and concepts ideal for college students studying programming and software development.

ZoeSparrow·48 flashcards·48 questions
collegecomputer_scienceprogramming
0
Known
1 / 48
0
Learning
Front

git init → what does it do?

Tap to flip
Back

Initializes a new Git repository in the current directory. Creates a .git subdirectory.

Tap to flip
Got it
Still learning

Quiz(48 questions)

Question 1 of 48

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?

A.To allow development on different versions of a project simultaneously.
B.To permanently delete previous commits.
C.To merge all changes into the master branch.
D.To restrict team members from making changes.

2. What command would you use to create a local copy of a remote repository?

A.git clone
B.git fetch
C.git push
D.git pull

3. What command initializes a new Git repository in the current directory?

A.git init
B.git start
C.git create
D.git new

4. Which command is used to stage changes for the next commit?

A.git add <file>
B.git commit
C.git stage
D.git save

5. Which command is used to create a new branch?

A.git branch <branch-name>
B.git new <branch-name>
C.git create <branch-name>
D.git add <branch-name>

6. Which command would you use to link your local repository to a remote repository?

A.git remote link
B.git remote add
C.git remote connect
D.git remote set

7. Which command is used to stage files for the next commit?

A.git add <file>
B.git stage <file>
C.git commit <file>
D.git include <file>

8. True or False: The command 'git add .' stages all changes within the current directory.

A.True
B.False
C.Only added files
D.Only modified files

9. What happens when you merge branches?

A.Changes from one branch are combined into another.
B.A new branch is created with no changes.
C.All branches are deleted after merging.
D.Only the source branch is kept after the operation.

10. True or False: The command 'git push' completely replaces the remote branch with the local branch.

A.True
B.False
C.It depends
D.Only in certain cases

11. What information can you get by running 'git status'?

A.Shows commit history
B.Displays branch information
C.Indicates modified, staged, and untracked files
D.Lists remote repositories

12. What is the effect of running 'git commit' without staging any changes?

A.All changes are committed
B.No changes are committed
C.Only staged changes are committed
D.An error occurs

13. What is a fast-forward merge?

A.It occurs when there are no new commits on the target branch.
B.It creates a new branch every time.
C.It requires manual conflict resolution.
D.It rewrites commit history.

14. What is the main function of the 'git fetch' command?

A.To download and merge changes
B.To delete remote branches
C.To retrieve updates without merging
D.To show remote branch history

15. Fill in the blank: 'git ___' commits the staged changes.

A.git update
B.git save
C.git commit
D.git push

16. What is the correct command to commit changes with a message?

A.git commit -m 'message'
B.git commit message
C.git commit --message 'message'
D.git commit -m message

17. Which command would you use to delete a branch?

A.git branch -d <branch-name>
B.git delete <branch-name>
C.git remove <branch-name>
D.git erase <branch-name>

18. What does the command 'git remote -v' do?

A.Lists all branches
B.Displays commit history
C.Shows configured remote repositories
D.Connects to a new remote

19. True or False: You can use 'git commit' without first running 'git add'.

A.True
B.False
C.Depends on the situation
D.Not applicable

20. Fill in the blank: To remove a file from the staging area, you would use ______.

A.git remove <file>
B.git reset <file>
C.git unstage <file>
D.git delete <file>

21. What does `git checkout -b <branch-name>` accomplish?

A.It creates a new branch and switches to it.
B.It deletes the current branch immediately.
C.It renames the existing branch.
D.It lists all branches in the repository.

22. What is the difference between 'git pull' and 'git fetch'?

A.They are the same command
B.git pull only downloads changes
C.git fetch merges changes automatically
D.git pull integrates remote changes into local branch

23. Which command displays a log of commits in the current branch?

A.git history
B.git log
C.git commits
D.git changes

24. Which of the following best describes the difference between 'git add' and 'git commit'?

A.Both stage changes
B.One stages and the other commits
C.Both save changes
D.One removes files

25. Which of the following statements about merge conflicts is NOT true?

A.They occur when changes to the same line in a file are made in different branches.
B.Git can always automatically resolve merge conflicts.
C.They require manual intervention to resolve.
D.They can arise during a merge operation.

26. What command should you use to unlink a remote repository from your local repository?

A.git remote delete
B.git remote unlink
C.git remote remove
D.git remote detach

27. What is the difference between 'git clone' and 'git init'?

A.Both create new repositories
B.git clone copies an existing repository, git init creates a new one
C.git clone initializes a repo, git init clones one
D.They are the same command

28. What does the command 'git status' display?

A.Changes in the staging area only
B.Changes in the repository only
C.State of working directory and staging area
D.List of commits

29. What is the effect of using branches in Git?

A.They isolate development work and facilitate multiple features.
B.They slow down the development process significantly.
C.They prevent any collaboration in a project.
D.They require constant updates to all branches.

30. What is the primary purpose of the 'git push' command?

A.To download remote changes
B.To upload local commits
C.To view remote status
D.To delete local branches

31. What does the command 'git remote add' accomplish?

A.Creates a new branch
B.Adds a remote repository
C.Commits changes
D.Clones a repository

32. What happens if you attempt to commit without providing a commit message?

A.The commit is saved without a message
B.Git prompts for a message
C.An error occurs
D.The commit is skipped

33. When is it necessary to switch branches before deleting one?

A.When the branch you want to delete is currently checked out.
B.When you want to create a new branch.
C.When you are merging changes.
D.When you are pulling updates from a remote repository.

34. How do you rename a remote repository connection?

A.git remote change
B.git remote edit
C.git remote rename
D.git remote update

35. If you run 'git rm <file>', what happens to the file?

A.The file is staged for commit
B.The file is deleted from the working directory
C.Both A and B
D.The file is ignored

36. What is the function of 'git commit --amend'?

A.To create a new commit
B.To modify the last commit
C.To delete the last commit
D.To view commit history

37. How does rebasing differ from merging?

A.Rebasing rewrites commit history for a linear progression.
B.Merging creates a linear commit history.
C.Rebasing is only for deleting branches.
D.Merging does not involve commit history.

38. Which command would provide detailed information about a specified remote repository?

A.git remote info
B.git remote details
C.git remote show
D.git remote status

39. What command would you use to discard local changes in a file?

A.git reset <file>
B.git restore <file>
C.git discard <file>
D.git checkout -- <file>

40. When staging multiple files, which command would you use?

A.git add .
B.git add file1.txt file2.txt
C.git add all
D.git commit all

41. What command would you use to switch to a branch?

A.git checkout <branch-name>
B.git switch <branch-name>
C.git move <branch-name>
D.git change <branch-name>

42. What can cause merge conflicts when using Git?

A.Different branch names
B.Commits from different users
C.Changes to the same line in a file
D.Merging unrelated branches

43. What is the purpose of the 'git config' command?

A.To configure repository settings
B.To create branches
C.To add remote repositories
D.To view commit logs

44. Which of the following is NOT a valid way to stage files?

A.git add <file>
B.git stage <file>
C.git add .
D.git add -A

45. If two developers are working on the same file and make conflicting changes, what should they do?

A.Manually resolve the conflicts before merging.
B.Delete one of the branches immediately.
C.Keep both changes and push them.
D.Ignore the conflict and merge anyway.

46. What does the command 'git remote prune origin' do?

A.Cleans up local branches
B.Removes unused local commits
C.Deletes remote branches
D.Cleans up remote-tracking branches that no longer exist

47. What does the command 'git branch' do?

A.Creates a new branch
B.Lists local branches
C.Switches branches
D.Deletes a branch

48. What is the primary purpose of commit messages in Git?

A.To describe changes
B.To create branches
C.To delete files
D.To revert changes

Related Study Sets

Create Your Own Study Set

Upload a PDF, paste your notes, or describe a topic – AI generates flashcards, quizzes and more in seconds.