Podcast
Questions and Answers
What is the primary function of Git?
What is the primary function of Git?
Which command is used to initialize a local Git repository?
Which command is used to initialize a local Git repository?
What does the .git/
directory contain?
What does the .git/
directory contain?
Which of the following statements is true about Git and GitHub?
Which of the following statements is true about Git and GitHub?
Signup and view all the answers
What is one of the main advantages of using Git for collaborative projects?
What is one of the main advantages of using Git for collaborative projects?
Signup and view all the answers
Which command would you use to change the name and email associated with your Git commits?
Which command would you use to change the name and email associated with your Git commits?
Signup and view all the answers
What is the primary purpose of GitHub as a service?
What is the primary purpose of GitHub as a service?
Signup and view all the answers
How is the .git/
directory classified in a file system?
How is the .git/
directory classified in a file system?
Signup and view all the answers
What command is used to merge changes from one branch into another?
What command is used to merge changes from one branch into another?
Signup and view all the answers
What is a good practice when naming feature branches?
What is a good practice when naming feature branches?
Signup and view all the answers
What does the git fetch
command do?
What does the git fetch
command do?
Signup and view all the answers
When using git pull
, what does the command accomplish?
When using git pull
, what does the command accomplish?
Signup and view all the answers
What command would you use to establish a connection to a remote repository if you cloned it initially?
What command would you use to establish a connection to a remote repository if you cloned it initially?
Signup and view all the answers
How do you initiate a project from an existing remote repository?
How do you initiate a project from an existing remote repository?
Signup and view all the answers
What happens when you run git push
?
What happens when you run git push
?
Signup and view all the answers
What is a necessary step before pushing changes if the remote branch has new changes?
What is a necessary step before pushing changes if the remote branch has new changes?
Signup and view all the answers
What is the use of commit messages in Git?
What is the use of commit messages in Git?
Signup and view all the answers
What command is used to set the user name globally in git?
What command is used to set the user name globally in git?
Signup and view all the answers
Which command will add all modified files in the Working Directory to the Staging Area?
Which command will add all modified files in the Working Directory to the Staging Area?
Signup and view all the answers
When creating a new branch, what command is used?
When creating a new branch, what command is used?
Signup and view all the answers
Which command is used to switch to a different branch in git?
Which command is used to switch to a different branch in git?
Signup and view all the answers
What does the HEAD pointer in a git repository represent?
What does the HEAD pointer in a git repository represent?
Signup and view all the answers
How can you commit specific files from the Staging Area?
How can you commit specific files from the Staging Area?
Signup and view all the answers
Why is the master branch important in a git repository?
Why is the master branch important in a git repository?
Signup and view all the answers
What flag must be used with the git commit command to include a message?
What flag must be used with the git commit command to include a message?
Signup and view all the answers
What is the purpose of the Staging Area in git?
What is the purpose of the Staging Area in git?
Signup and view all the answers
What command would you use to push local changes to a remote repository?
What command would you use to push local changes to a remote repository?
Signup and view all the answers
What does the command 'git add ' do?
What does the command 'git add
Signup and view all the answers
How can you create a branch and switch to it in a single command?
How can you create a branch and switch to it in a single command?
Signup and view all the answers
What happens when a change is made to a tracked file in a git repository?
What happens when a change is made to a tracked file in a git repository?
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.
- Creates a hidden
- 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
.
- Check status with
- Staging Area: Holds changes ready for commit.
- Add specific files to staging area with
git add <filename>
. - Add all changes with
git add .
.
- Add specific files to staging area with
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
- Stage changes (
git add .
). - Commit staged changes (
git commit -m "Message"
). - Pull down remote changes to your own (
git pull
). - Push your local changes now. (
git push
).
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
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.