Daily Git Usage and Extensions
Learn common Git commands, branch naming conventions, and extensions like Git LFS and git‑flow.
Summary
Read Summary
Flashcards
Save Flashcards
Quiz
Take Quiz
Quick Practice
Which command creates a new Git repository in the current directory?
1 of 16
Summary
Common Git Commands and Workflows
Introduction
Git is a distributed version control system that allows you to track changes to your code, collaborate with others, and maintain a complete history of your project. This guide covers the essential commands and workflows you need to understand Git's fundamental operations.
Core Commands
Starting a Repository
When you begin a new project with Git, you have two primary options. If you're starting from scratch, git init creates a new Git repository in your current directory. This initializes the necessary Git data structures and creates your first branch (typically named master or main).
When working with an existing project, git clone <URL> downloads a complete copy of that repository. This includes all the project history, branches, and files, giving you a fully functional local copy to work with.
The Commit Workflow
Git's core workflow revolves around staging and committing changes. Think of this as a two-step process:
Staging prepares your changes for commit using git add <file>. When you modify files, Git doesn't automatically track those changes—you explicitly tell Git which files you want to include in your next commit by adding them to the staging area. This gives you fine-grained control over what goes into each commit.
Committing permanently records staged changes using git commit -m <message>. Your commit message should clearly describe what changed and why. The commit becomes part of your permanent project history.
Managing Files to Ignore
Not everything in your project directory should be tracked by Git. Configuration files, dependency folders, build outputs, and system files should be excluded. You specify what Git should ignore by creating a file named .gitignore in your repository root. This plain-text file uses patterns to match filenames and directories that Git should skip.
For example, a .gitignore file might contain:
nodemodules/
.log
.env
pycache/
This tells Git to ignore the nodemodules directory, all .log files, the .env file, and Python's pycache directory.
Understanding Git Branches and Remote Repositories
Default Branch Names
When you initialize a repository with git init, Git creates an initial branch. Historically, this branch was named master, but the Git community has moved toward main as the default name. Many hosting services like GitHub now use main by default. Both names refer to the same concept—your primary development branch—so you'll encounter both in practice.
Remote Repositories
A remote is a reference to another Git repository, typically hosted on a server. When you clone a repository, Git automatically creates a remote named origin, which points back to the original repository you cloned from. This is a convention: "origin" is simply the standard name for the default upstream repository.
Collaborative Workflows
Pull Requests
A pull request (also called a merge request on some platforms) is a formalized way to propose merging changes from one branch into another. Rather than directly merging branches yourself, you create a pull request that allows others to review your changes, discuss them, and approve the merge. This is enforced by hosting platforms like GitHub and GitLab—it's not a Git command itself, but rather a feature built on top of Git's branching system.
Pull requests are essential for team development because they enable code review and prevent untested or problematic code from entering your main branches.
Handling Committed Changes
A key principle in Git workflow is: once you've pushed commits to a shared repository, you generally don't rewrite them. Instead, if you need to undo changes, you create a new commit that reverses the earlier changes. This preserves the historical record and prevents conflicts with other developers who may have based their work on the pushed commits.
Branch Naming Conventions
When working on a project with multiple developers, consistent branch naming helps everyone understand what each branch is for:
Feature branches are typically prefixed with feature/ (for example, feature/user-authentication) and contain new functionality under development.
The develop branch serves as the integration point for features being developed. It contains unstable, in-progress code and is shared among developers.
The main branch (or master in older projects) holds only production-ready code. Releases come from this branch, ensuring that what users see is stable and tested.
<extrainfo>
Hotfix branches are used for emergency patches to released products. When a critical bug is discovered in production, a hotfix branch allows you to make and test the fix quickly while keeping the develop branch unaffected.
</extrainfo>
<extrainfo>
Advanced Topics
Renaming the Default Branch
Existing repositories can change their default branch name using git branch -m master main followed by updating remote configuration. This is a useful administrative task when adopting the newer naming convention, though it doesn't affect Git's underlying data structures. However, teams using continuous-integration systems or automated deployment may need to update scripts and documentation accordingly.
Git Extensions
Git Large File Storage (Git LFS) is an extension for projects that need to version-control large files (such as videos, datasets, or binaries). Rather than storing these large files directly in your repository, Git LFS stores lightweight pointers to them while the actual files are kept outside the regular repository. This keeps your repository slim and fast.
git-flow is another extension that provides high-level commands implementing a specific branching model (Vincent Driessen's model). Instead of manually managing branches, git-flow automates branch creation and merging following a standardized workflow. This is particularly useful for teams with formal release cycles.
</extrainfo>
Flashcards
Which command creates a new Git repository in the current directory?
git init
Which command duplicates an existing Git repository from a specified URL?
git clone <URL>
Which command adds a specific file to the staging area to prepare it for a commit?
git add <file>
Which command records staged changes as a new commit with a specific message?
git commit -m <commit message>
What is the recommended practice for undoing pushed commits instead of overwriting history?
Adding a new commit that reverts the changes
What is the name of the plain-text file used to list patterns for files Git should not track?
.gitignore
What are the common default branch names used by git init and hosting services?
master (default for git init)
main (common default for hosting services)
Which command is used to rename the local master branch to main?
git branch -m master main
What is the standard default name given to an upstream remote repository?
origin
What prefix is commonly used when naming feature branches?
feature/
In common workflows, which branch is used specifically for unstable shared history?
The develop branch
In common workflows, which branch holds the production-ready history?
The main branch
What type of branch is used for emergency patches to released products?
Hotfix branches
Who or what manages pull requests (merge requests) instead of Git itself?
Hosting services
How does Git LFS (Large File Storage) handle large files to keep the repository efficient?
It stores large files externally and keeps lightweight pointers inside the repository
What specific branching model is implemented by the git-flow extension?
Vincent Driessen’s branching model
Quiz
Daily Git Usage and Extensions Quiz Question 1: What is the default name for the upstream remote repository in Git?
- origin (correct)
- upstream
- remote
- central
Daily Git Usage and Extensions Quiz Question 2: Which command renames the default branch from “master” to “main”?
- git branch -m master main (correct)
- git checkout -b main master
- git rename-branch master main
- git branch --rename master main
Daily Git Usage and Extensions Quiz Question 3: What is the recommended way to undo a change that has already been pushed to a shared repository?
- Add a new commit that reverts the earlier changes (correct)
- Amend the original commit and force‑push
- Delete the remote branch and recreate it
- Reset the local branch to an earlier commit without pushing
Daily Git Usage and Extensions Quiz Question 4: Which prefix is commonly used for feature branches?
- feature/ (correct)
- bugfix/
- release/
- hotfix/
Daily Git Usage and Extensions Quiz Question 5: What is the typical purpose of a <code>develop</code> branch in Git workflows?
- Integration branch for unstable shared work (correct)
- Branch that holds production‑ready code
- Branch used exclusively for emergency patches
- Default branch created by <code>git init</code>
Daily Git Usage and Extensions Quiz Question 6: What kind of history does the <code>main</code> branch usually contain?
- Production‑ready history (correct)
- Experimental feature work
- Unstable integration changes
- Personal development commits
Daily Git Usage and Extensions Quiz Question 7: What does Git Large File Storage (Git LFS) store outside the regular Git repository?
- Large file contents (correct)
- Commit messages
- Branch metadata
- Repository configuration files
Daily Git Usage and Extensions Quiz Question 8: After running <code>git init</code> in an empty directory, which of the following appears?
- A hidden <code>.git</code> directory is created (correct)
- A new branch named <code>develop</code> is created
- A remote named <code>origin</code> is automatically added
- The repository is immediately pushed to GitHub
Daily Git Usage and Extensions Quiz Question 9: Which command stages the file <code>README.md</code> for the next commit?
- <code>git add README.md</code> (correct)
- <code>git commit README.md</code>
- <code>git push README.md</code>
- <code>git init README.md</code>
Daily Git Usage and Extensions Quiz Question 10: Where would you place a pattern to make Git ignore all files ending with <code>.log</code>?
- In a file named <code>.gitignore</code> (correct)
- In the repository’s <code>README.md</code> file
- As a command‑line argument to <code>git add</code>
- In the <code>.gitattributes</code> file
Daily Git Usage and Extensions Quiz Question 11: Which two branch names are commonly used as the default branch for new Git repositories?
- <code>master</code> and <code>main</code> (correct)
- <code>develop</code> and <code>release</code>
- <code>feature</code> and <code>hotfix</code>
- <code>staging</code> and <code>production</code>
Daily Git Usage and Extensions Quiz Question 12: On a platform such as GitHub, which feature enables team members to discuss and review code before it is merged?
- Pull request (correct)
- Branch protection rule
- Tag annotation
- Git rebase
Daily Git Usage and Extensions Quiz Question 13: After renaming the default branch of a repository, which of the following typically needs to be updated?
- Continuous‑integration scripts and documentation (correct)
- The repository’s commit hashes
- The underlying .git object database
- The file system permissions of the .git directory
Daily Git Usage and Extensions Quiz Question 14: Which Git extension adds commands like <code>git flow init</code> and <code>git flow feature start</code> to manage branches?
- git‑flow (correct)
- git‑lfs
- git‑annex
- git‑gui
Daily Git Usage and Extensions Quiz Question 15: Which Git command creates a local copy of a repository from a given URL?
- git clone <URL> (correct)
- git pull <URL>
- git fetch <URL>
- git init <URL>
What is the default name for the upstream remote repository in Git?
1 of 15
Key Concepts
Git Basics
Git
.gitignore
Default branch (master/main)
Origin
Git add
Git Large File Storage (Git LFS)
Collaboration and Workflow
Pull request
Branch naming conventions
Git init
Git clone
Git commit
git‑flow
Definitions
Git
A distributed version‑control system for tracking changes in source code and other files.
Git init
A command that creates a new empty Git repository in the current directory.
Git clone
A command that copies an existing remote repository to a local machine.
Git add
A command that stages specified files, preparing them to be included in the next commit.
Git commit
A command that records staged changes as a new snapshot in the repository’s history.
.gitignore
A plain‑text file that lists file patterns Git should ignore and not track.
Default branch (master/main)
The initial branch created by Git, traditionally named master but increasingly named main.
Origin
The default name for a repository’s primary remote location.
Pull request
A request, typically managed by a hosting service, to merge changes from one branch into another.
Git Large File Storage (Git LFS)
An extension that stores large files outside the repository while keeping lightweight pointers.
git‑flow
A set of high‑level Git commands that implement a structured branching model for development.
Branch naming conventions
Standardized prefixes (e.g., feature/, develop, hotfix/) used to identify the purpose of branches.