Git and GitHub Overview Quiz
30 Questions
1 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is the primary function of Git?

  • To provide cloud storage for files
  • To manage database servers
  • To host web applications remotely
  • To track changes to source code during development (correct)
  • Which command is used to initialize a local Git repository?

  • git new
  • git start
  • git create
  • git init (correct)
  • What does the .git/ directory contain?

  • A cache of remote repository files
  • Only the source code files
  • The entire history of the project along with commit information (correct)
  • User personal settings and preferences
  • Which of the following statements is true about Git and GitHub?

    <p>GitHub provides additional features like access control beyond Git’s capabilities.</p> Signup and view all the answers

    What is one of the main advantages of using Git for collaborative projects?

    <p>It enables easy branching and merging of code changes</p> Signup and view all the answers

    Which command would you use to change the name and email associated with your Git commits?

    <p>git config</p> Signup and view all the answers

    What is the primary purpose of GitHub as a service?

    <p>To host Git repositories in the cloud</p> Signup and view all the answers

    How is the .git/ directory classified in a file system?

    <p>As a hidden directory not visible by default</p> Signup and view all the answers

    What command is used to merge changes from one branch into another?

    <p>git merge</p> Signup and view all the answers

    What is a good practice when naming feature branches?

    <p>Base branch names on the features they pertain to</p> Signup and view all the answers

    What does the git fetch command do?

    <p>Only downloads changes from a remote repository without committing</p> Signup and view all the answers

    When using git pull, what does the command accomplish?

    <p>Fetches and commits the latest changes from a remote repository</p> Signup and view all the answers

    What command would you use to establish a connection to a remote repository if you cloned it initially?

    <p>git remote add</p> Signup and view all the answers

    How do you initiate a project from an existing remote repository?

    <p>Run the <code>git clone</code> command with the repository’s URL.</p> Signup and view all the answers

    What happens when you run git push?

    <p>It sends local commits to the remote repository.</p> Signup and view all the answers

    What is a necessary step before pushing changes if the remote branch has new changes?

    <p>Run <code>git pull</code> to ensure all changes are updated locally.</p> Signup and view all the answers

    What is the use of commit messages in Git?

    <p>To document the changes made in a commit</p> Signup and view all the answers

    What command is used to set the user name globally in git?

    <p>git config --global user.name 'YOUR NAME'</p> Signup and view all the answers

    Which command will add all modified files in the Working Directory to the Staging Area?

    <p>git add .</p> Signup and view all the answers

    When creating a new branch, what command is used?

    <p>git branch new-feature</p> Signup and view all the answers

    Which command is used to switch to a different branch in git?

    <p>git checkout [branch-name]</p> Signup and view all the answers

    What does the HEAD pointer in a git repository represent?

    <p>The latest commit of the currently active branch</p> Signup and view all the answers

    How can you commit specific files from the Staging Area?

    <p>git commit file1 file2</p> Signup and view all the answers

    Why is the master branch important in a git repository?

    <p>It holds the production-ready project code.</p> Signup and view all the answers

    What flag must be used with the git commit command to include a message?

    <p>-m</p> Signup and view all the answers

    What is the purpose of the Staging Area in git?

    <p>It temporarily holds changes before they are committed.</p> Signup and view all the answers

    What command would you use to push local changes to a remote repository?

    <p>git push</p> Signup and view all the answers

    What does the command 'git add ' do?

    <p>Stages the specified file for the next commit.</p> Signup and view all the answers

    How can you create a branch and switch to it in a single command?

    <p>git checkout -b my-feature-branch</p> Signup and view all the answers

    What happens when a change is made to a tracked file in a git repository?

    <p>The change is recorded in the Working Directory.</p> Signup and view all the answers

    Study Notes

    Git and GitHub Overview

    • Git is a distributed version control system for tracking code changes.
    • A local repository contains the entire project history, enabling efficient branching and merging.
    • GitHub is a cloud-based Git repository hosting service.
    • Other popular options include GitLab, Bitbucket, and SourceForge.
    • GitHub provides additional features like access control, wikis, and issue boards.

    Initializing Repositories

    • Initialize a local repository using git init in the desired directory.
      • Creates a hidden .git directory containing repository information.
    • Configure Git with your name and email using git config:
      • git config --global user.name "Your Name"
      • git config --global user.email "[email protected]"
    • Add your email address on GitHub to attribute commits to your profile and contributions graph.

    Working Directory and Staging Area

    • Working Directory: Stores untracked and modified files since the last commit.
      • Check status with git status.
    • Staging Area: Holds changes ready for commit.
      • Add specific files to staging area with git add <filename>.
      • Add all changes with git add ..

    Committing Locally

    • Commit changes from the staging area using git commit -m "Your Commit Message".
    • Use commit messages to explain changes made.
    • Optionally, specify files to commit with git commit <filename> -m "..." for specific files.

    Pushing to Remote

    • git push: Uploads local changes to a remote repository.
    • Conventionally, the remote branch name mirrors the local branch.
      • origin is a common remote alias.

    Git Branching

    • master branch: Holds production-ready code.
    • Branches are timelines of project updates, created through snapshots of the parent branch.
    • Create a new local branch with git branch <branch-name>.
    • Switch to another branch with git checkout <branch-name>.
    • Create and switch at once with git checkout -b <branch-name>.
    • Merge changes from one branch to another:
      • git merge <branch-name> (on the target branch) - from command line.
      • Usually involves a pull request to merge on GitHub rather than using git merge locally.

    Working with Remote Repositories (Command Line)

    • git clone <remote-repo-address>: Clones a remote repository locally.
    • git remote add <alias> <remote-repo-address>: Adds a remote repo manually; origin common.
    • git remote -v: Lists connected remote repositories.
    • git fetch <remote> <branch>: Downloads changes from the remote; does not commit.
    • git pull <remote> <branch>: Fetches and merges remote changes to local. Avoids conflicts.
    • Git pull without arguments defaults to fetching the repository/branch.

    Pull Requests (GitHub)

    • Create pull requests to merge branches on GitHub.
    • Choose the source and target branch using the "compare" and "base" dropdowns.
    • Click on "Create pull request".
    • Merge the changes after review.

    Commit Workflow Recipe

    1. Stage changes (git add .).
    2. Commit staged changes (git commit -m "Message").
    3. Pull down remote changes to your own (git pull).
    4. Push your local changes now. (git push).

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Description

    Test your knowledge of Git and GitHub with this comprehensive quiz. Learn about version control systems, initializing repositories, and the working directory. Perfect for those looking to improve their skills in version control and collaboration using GitHub.

    More Like This

    Git Basics Quiz
    10 questions
    Version Control and Git Basics
    8 questions
    Git Basics for TYPO3 Integrators
    40 questions
    Use Quizgecko on...
    Browser
    Browser