PLAINFINCH learn by building

Every Git command

  • .cpanel.yml A file that tells a cPanel host which deployment steps to run after a push.
  • .env file A file that holds private keys and settings, which should never be committed.
  • .gitignore A file listing patterns for files and folders Git should leave untracked.
  • ahead and behind How many commits your branch has that the remote lacks, and the other way round.
  • branch A movable label for a line of work, so changes can grow apart from main.
  • CNAME file A file on GitHub Pages that names the custom domain your site should use.
  • commit A saved snapshot of your project with a message, an author and a unique id.
  • conflict markers The <<<<<<<, ======= and >>>>>>> lines Git adds to show both sides of a conflict.
  • detached HEAD A state where HEAD points at a commit rather than a branch, so new work can drift away.
  • fast-forward A merge where Git simply moves the branch label ahead because nothing diverged.
  • git add -A Stage all changes in the whole repository, including deleted files.
  • git add -f Stage a file even though a .gitignore pattern would normally skip it.
  • git add -u Stage changes to files Git already tracks, leaving new files alone.
  • git add . Stage every new and changed file in this folder and the folders below it.
  • git add <file> Put a file's current changes into the staging area, ready for the next commit.
  • git branch List your local branches and mark the one you are on.
  • git branch -a List local branches along with the remote-tracking ones such as origin/main.
  • git branch -d Delete a branch whose work has already been merged somewhere safe.
  • git branch -D Force-delete a branch even if its commits have not been merged.
  • git branch -m Rename a branch, for example to fix a typo in its name.
  • git branch <name> Create a new branch at the current commit without switching to it.
  • git checkout -- <file> The older way to discard edits to a file, still seen in many guides.
  • git checkout -b The older way to create a branch and switch to it at the same time.
  • git checkout <branch> The older command for moving to another branch, still widely used.
  • git clean -f Delete untracked files from your folder for good.
  • git clean -fd Delete untracked files and untracked folders, which cannot be undone.
  • git clean -n Preview which untracked files git clean would delete, without deleting anything.
  • git clone Download a full copy of a remote repository, history and all, into a new folder.
  • git commit --amend Replace your last commit with a corrected one that includes what is staged now.
  • git commit --amend --no-edit Add staged changes to your last commit and keep its message as it was.
  • git commit --amend -m Give your most recent commit a new message without making a new commit.
  • git commit -am Stage changes to tracked files and commit them in one step.
  • git commit -m Save everything in the staging area as a new commit with the message you give.
  • git config user.email Set the email address that Git records alongside your commits.
  • git config user.name Set the name that Git writes into each commit you make.
  • git diff Show the lines you have changed in your files but not staged yet.
  • git diff --staged Show the changes that are staged and will go into the next commit.
  • git diff <a> <b> Compare two commits or branches and show every line that differs between them.
  • git fetch Download new commits from the remote without changing your own branches.
  • git init Turn the current folder into a new repository so Git can start tracking it.
  • git log List the commits on this branch, newest first, with author, date and message.
  • git log --all Include commits from every branch in the log, not just the one you are on.
  • git log --oneline Show each commit on one line with its short id and summary.
  • git log -n Limit the log to the most recent few commits, for example git log -n 3.
  • git merge Bring the commits from another branch into the branch you are on.
  • git merge --abort Cancel a merge that hit conflicts and go back to how things were before.
  • git merge --no-ff Merge with a merge commit even when a simple fast-forward would work.
  • git mv Rename or move a tracked file and stage the change in one step.
  • git pull Fetch new commits from the remote and merge them into your current branch.
  • git push Send your new commits on this branch up to the remote.
  • git push --force Overwrite the remote branch with yours, which can wipe out other people's work.
  • git push -u origin <branch> Push a branch for the first time and remember the remote branch it tracks.
  • git reflog List every place HEAD has pointed recently, so you can find lost commits.
  • git remote -v List the remotes this repository knows about and their addresses.
  • git remote add Connect your repository to a remote, usually called origin, at a given URL.
  • git remote remove Disconnect a remote from your repository without touching any files.
  • git remote set-url Change the address a remote points to, for example after renaming a repo.
  • git reset --hard Move the branch back and erase uncommitted changes, which cannot be undone easily.
  • git reset --mixed Move the branch back and keep the changes in your files, but unstaged.
  • git reset --soft Move the branch back to an earlier commit and keep those changes staged.
  • git reset <file> Unstage a file, the same as git restore --staged in older style.
  • git restore --source Bring back a file exactly as it was in an older commit you name.
  • git restore --staged Take a file out of the staging area while keeping your edits in the file.
  • git restore . Discard all unstaged edits in this folder at once, so use it with care.
  • git restore <file> Throw away unstaged edits to a file and bring back its last saved version.
  • git revert Make a new commit that undoes an earlier one, leaving history intact.
  • git rm Delete a tracked file and stage that deletion for the next commit.
  • git rm --cached Stop tracking a file but leave it in your folder, often after adding it to .gitignore.
  • git show Display one commit's message along with the exact changes it made.
  • git stash Set uncommitted changes aside so you have a clean working folder for a while.
  • git stash apply Bring back stashed changes but keep a copy of them in the stash.
  • git stash list Show every set of changes you have stashed away.
  • git stash pop Bring back your most recently stashed changes and remove them from the stash.
  • git status Show which branch you are on and which files are new, changed or staged.
  • git status -s Print a short status with one line per file and a two-letter code.
  • git switch Move to another branch so your files match the commits on it.
  • git switch -c Create a new branch and move onto it in one command.
  • GitHub A website that hosts Git repositories online so you can share and back them up.
  • GitHub Pages A free GitHub service that publishes a repository's files as a website.
  • HEAD A pointer to the commit you are on now, usually the tip of your current branch.
  • HEAD~1 The commit just before HEAD; HEAD~2 goes back two, and so on.
  • main The usual name for a repository's primary branch.
  • merge commit A commit with two parents that joins the histories of two branches.
  • merge conflict What happens when two branches change the same lines and Git needs you to choose.
  • origin The name Git gives by default to the remote you cloned from or first added.
  • origin/main Your local record of where main was on the remote the last time you fetched.
  • pull request A request on GitHub to review a branch's changes and merge them into another branch.
  • rejected push Git refusing your push because the remote has commits you have not pulled yet.
  • remote Another copy of your repository, usually on GitHub, that you push to and pull from.
  • repository A project folder plus the full history of saved versions Git keeps for it.
  • secret scanning A GitHub check that warns you when a password or key lands in a pushed commit.
  • staging area The waiting room where you collect changes before saving them as a commit.
  • untracked file A file in your folder that Git has not been told to follow yet.
  • upstream branch The remote branch your local branch is linked to for plain push and pull.
  • working folder The files you see and edit, which may differ from the last commit.