By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
(For engineers who need to set up repos fast, avoid identity crises, and automate workflows—without the theory overload.)
You’re joining a new team, inheriting a legacy project, or spinning up a fresh repo for a microservice. Three commands will make or break your first commit:- git init (creates a repo from scratch) - git clone (copies an existing repo) - git config (sets your identity and shortcuts)
git init
git clone
git config
Why this matters in production:- git init is your "start from zero" tool. Mess this up, and you’ll either: - Accidentally commit to the wrong directory (e.g., your ~/Downloads folder). - Forget to initialize Git, then wonder why git status says "fatal: not a git repository".- git clone is how you onboard to a project. If you clone the wrong URL (HTTPS vs. SSH), you’ll waste 20 minutes debugging authentication errors.- git config sets your user.name and user.email. If these are wrong: - Your commits will show up as "Unknown Author" in GitHub/GitLab. - Your team’s CI/CD pipeline might reject your PRs (e.g., GitHub Actions enforcing verified emails). - Aliases (like git co for git checkout) save you hours over a year. Not setting them is like typing ls -la instead of ll—small friction, big cumulative cost.
~/Downloads
git status
user.name
user.email
git co
git checkout
ls -la
ll
Real-world scenario:You’re a DevOps engineer deploying a new service. You: 1. git init a fresh repo for infrastructure-as-code (Terraform/Ansible).2. git clone the team’s shared templates repo to copy best practices.3. git config your work email (not your personal one) so commits are tied to your corporate GitHub account.4. Set up aliases like git cm for git commit -m to speed up your workflow.
git cm
git commit -m
If you skip this, you’ll:- Commit with the wrong identity (e.g., your personal email on a work project).- Waste time typing full commands instead of aliases.- Struggle to collaborate because your local repo isn’t properly linked to GitHub.
.git
/
~
--initial-branch=main
master
--depth=1
git clone --depth=1 https://github.com/kubernetes/kubernetes
--mirror
--global
--local
--system
git st
~/.gitconfig
git lg
.git/
.git/config
.gitignore
git remote
origin
upstream
git acp
git add . && git commit -m "$1" && git push
git log --oneline --graph --decorate --all
git --version
git version 2.x.x
Goal: Create a local repo, commit a file, and push to GitHub.
Create a project folder: bash mkdir my-project && cd my-project
bash mkdir my-project && cd my-project
Initialize Git: bash git init --initial-branch=main
bash git init --initial-branch=main
Verify: ls -a should show a .git folder.
ls -a
Create a file and commit: bash echo "# My Project" > README.md git add README.md git commit -m "Initial commit"
bash echo "# My Project" > README.md git add README.md git commit -m "Initial commit"
Create a GitHub repo:
my-project
Copy the HTTPS or SSH URL (e.g., https://github.com/your-username/my-project.git).
https://github.com/your-username/my-project.git
Link local repo to GitHub: bash git remote add origin https://github.com/your-username/my-project.git
bash git remote add origin https://github.com/your-username/my-project.git
Verify: git remote -v should show origin with the URL.
git remote -v
Push to GitHub: bash git push -u origin main
bash git push -u origin main
-u
origin/main
git push
Goal: Clone a repo (e.g., a team project) and verify it works.
On GitHub, click Code and copy the HTTPS or SSH URL.
Clone the repo: bash git clone https://github.com/your-team/team-project.git cd team-project
bash git clone https://github.com/your-team/team-project.git cd team-project
Verify: git log -1 should show the latest commit.
git log -1
Check remotes: bash git remote -v
bash git remote -v
Goal: Set your user.name/user.email and create time-saving aliases.
bash git config --global user.name "Your Name" git config --global user.email "[email protected]"
Verify: git config --global --list should show your name/email.
git config --global --list
Set local identity (override global for a specific repo): bash git config user.name "Work Name" git config user.email "[email protected]"
bash git config user.name "Work Name" git config user.email "[email protected]"
Verify: git config --list (shows local settings).
git config --list
Create aliases: bash git config --global alias.co checkout git config --global alias.br branch git config --global alias.ci commit git config --global alias.st status git config --global alias.lg "log --oneline --graph --decorate --all" git config --global alias.acp "!git add . && git commit -m '$1' && git push"
bash git config --global alias.co checkout git config --global alias.br branch git config --global alias.ci commit git config --global alias.st status git config --global alias.lg "log --oneline --graph --decorate --all" git config --global alias.acp "!git add . && git commit -m '$1' && git push"
Test: git st should work like git status.
Edit aliases manually (optional):
ini [alias] co = checkout br = branch ci = commit st = status lg = log --oneline --graph --decorate --all acp = !git add . && git commit -m \"$1\" && git push
git acp "My commit message"
bash git remote set-url origin [email protected]:user/repo.git
bash git clone --depth=1 https://github.com/large-repo.git
bash git clone --filter=blob:none --sparse https://github.com/monorepo.git cd monorepo git sparse-checkout init --cone git sparse-checkout set path/to/subdir
.DS_Store
bash echo ".env" >> .gitignore echo "node_modules/" >> .gitignore
bash git tag -a v1.0.0 -m "Release v1.0.0" git push origin v1.0.0
bash git lg
~/
cd
pwd
git config --global user.name "Your Name"
git clone [email protected]:user/repo.git
git push -u origin main
git alias-name
Typical question patterns:1. "What’s the difference between git init and git clone? - git init creates a new repo; git clone copies an existing one. - Trap: "They do the same thing" (wrong—they’re opposites).
Trap: Forgetting --global (sets it only for the current repo).
"What’s the purpose of git remote add origin?
git remote add origin
Trap: "It creates a remote repo" (wrong—it just links to an existing one).
"How do you create a Git alias for git status?
git config --global alias.st status
Trap: Using = (e.g., alias.st=status—wrong syntax).
=
alias.st=status
"What happens if you run git init in a folder with an existing .git directory?"
Scenario-based question:"You cloned a repo but your commits show as 'Unknown Author' in GitHub. What’s the fix?" - Answer: Set user.name and user.email to match your GitHub account: bash git config --global user.name "Your GitHub Username" git config --global user.email "[email protected]"
bash git config --global user.name "Your GitHub Username" git config --global user.email "[email protected]"
Challenge:1. Initialize a new Git repo in a folder called challenge-repo.2. Create a file notes.txt with the text "Hello, Git!".3. Commit the file with the message "Add notes".4. Set a local user.email to [email protected] (override any global setting).5. Create an alias git unstage that runs git reset HEAD --.6. Verify all steps with git log, git config --list, and git alias.
challenge-repo
notes.txt
[email protected]
git unstage
git reset HEAD --
git log
git alias
Solution:
mkdir challenge-repo && cd challenge-repo git init --initial-branch=main echo "Hello, Git!" > notes.txt git add notes.txt git commit -m "Add notes" git config user.email "[email protected]" git config --global alias.unstage "reset HEAD --" git log # Verify commit git config --list # Verify email git alias # Verify alias
Why it works:- git init creates the repo.- git config user.email overrides the global setting for this repo.- git config --global alias.unstage creates a reusable shortcut.
git config user.email
git config --global alias.unstage
git init --initial-branch=main
main
git clone <url>
[email protected]:user/repo.git
git remote add origin <url>
git config --global user.name "Name"
git config --global user.email "[email protected]"
log --oneline --graph --decorate --all
git acp "message"
git last
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.