PHP / CLI documentation browser

Git Search Tool

Maximum-coverage Git Q&A, workflows, troubleshooting, and command reference.

50 entries
Most-Used WorkflowstutorialCommit and push normal changesWhat is the standard edit, commit, and push sequence?

After editing and testing:

git status
git add -A
git commit -m "Describe the change"
git push

Use git add file1 file2 instead of git add -A when you only want selected files in the commit.

Source: Session workflow · Tags: daily, add, commit, push, workflow · Link
Most-Used WorkflowscheatInspect an old released file without changing current filesHow do I quickly view README.md from v1?
git show v1:README.md

Save it to a separate file if needed:

git show v1:README.md > README.v1.md
Source: Session workflow · Tags: show, old version, README, tag · Link
Most-Used WorkflowscheatQuick safety check before pull or pushWhat should I check before synchronizing?
git status
git branch --show-current
git rev-parse --abbrev-ref @{u}

This shows uncommitted work, the current branch, and its tracking branch.

Source: Session workflow · Tags: status, branch, upstream, safety, pull, push · Link
Most-Used WorkflowstutorialRelease a tested versionWhat is the short recipe for a new release?

After release changes are committed and tested:

./git-bump-version 3.0.0
git push origin main
git push origin --tags

The helper updates VERSION, commits it, and creates tag v3.0.0. The two pushes publish the branch and tag.

Source: Session workflow · Tags: release, VERSION, tag, bump, push · Link
Most-Used WorkflowstutorialStart a normal work sessionWhat commands should I run before editing?

From a working copy:

git status
git checkout main
git pull

Resolve, commit, stash, or discard uncommitted work before pulling if Git reports a conflict or refuses to merge.

Source: Session workflow · Tags: daily, pull, main, status, workflow · Link
Setup & SSHfaqBare repo has no branches or show-ref returns 1What does empty output and exit code 1 from git show-ref mean?

A newly initialized bare repo has no commits, branches, tags, or refs. git show-ref can print nothing and return 1. Push an initial commit from a working copy to create main.

git --git-dir=/home/intel145/websites/gitrepo/defapp.git show-ref
Source: Session Q&A · Tags: show-ref, exit 1, empty repository, bare, branches · Link
Setup & SSHglossaryBare repository versus working copyWhich folder do I edit, and which folder stores the remote repository?

A bare repository is central storage with no checked-out files, such as /home/intel145/websites/gitrepo/proj1.git. Do not edit or run normal git add/git commit work there.

A working copy is where you edit, test, stage, commit, and push, such as ~/projects/proj1 on macOS or /home/intel145/websites/apps/proj1 on Linux.

Source: tasks.md · Tags: bare repo, working copy, git.git, apps, server · Link
Setup & SSHtutorialClone current project from the SSH serverHow do I get the current version of a project from the remote repository?

Use the ssh:// URL form so the custom port is included:

mkdir -p ~/projects
cd ~/projects
git clone ssh://intel145@209.182.212.74:2222/home/intel145/websites/gitrepo/proj1.git proj1
cd proj1

Verify:

git remote -v
git branch -a
cat VERSION
git describe --tags --always
Source: faq4.md · Tags: clone, ssh, remote, current version, macos, linux · Link
Setup & SSHtutorialConfigure SSH once for port 2222 and keyHow do I avoid typing SSH port and identity options every time?

Add a host entry to ~/.ssh/config on the client machine:

Host gitserver
    HostName 209.182.212.74
    User intel145
    Port 2222
    IdentityFile ~/.ssh/id_rsa
    IdentitiesOnly yes

Then test with ssh gitserver 'echo SSH_OK'. You can use gitserver:/home/intel145/... in scp-style Git URLs afterward.

Source: Session Q&A · Tags: ssh config, port 2222, identityfile, id_rsa · Link
Setup & SSHtaskConfirm SSH access to the Git serverHow do I confirm SSH works before using Git?

Run from macOS or another Linux client:

ssh -p 2222 intel145@209.182.212.74 'echo SSH_OK'

If it prints SSH_OK, SSH connectivity works. Git over SSH will not work until this succeeds.

Source: tasks.md · Tags: ssh, server, port 2222, key, connection · Link
Setup & SSHtaskSet Git author identityWhy might commit fail with unknown author identity?

Set your commit identity once on a development machine:

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

Check it with:

git config --global --list | grep '^user\.'
Source: Session Q&A · Tags: user.name, user.email, commit, identity · Link
Setup & SSHtaskVerify a bare repository is validHow do I make sure a bare repository is correct?
git --git-dir=/home/intel145/websites/gitrepo/proj1.git rev-parse --is-bare-repository
git --git-dir=/home/intel145/websites/gitrepo/proj1.git fsck --full
git --git-dir=/home/intel145/websites/gitrepo/proj1.git show-ref

true confirms a bare repo. A fresh repo may have no refs until an initial commit is pushed.

Source: Session Q&A · Tags: bare, fsck, show-ref, integrity, repository · Link
Setup & SSHfaqWhy git branch fails in the bare-repository parent folderWhy did git branch say not a git repository in websites/gitrepo?

/home/intel145/websites/gitrepo is a container holding several bare repositories; it is not itself a repository. Point Git at one actual bare repo:

git --git-dir=/home/intel145/websites/gitrepo/defapp.git branch -a

For normal editing, clone it into a working copy.

Source: Session Q&A · Tags: not a git repository, bare, parent folder, git branch · Link
Remote & SynctaskCheck or repair a configured remoteHow do I check or fix the remote URL?

Inspect remotes:

git remote -v

Update an existing remote:

git remote set-url origin ssh://intel145@209.182.212.74:2222/home/intel145/websites/gitrepo/proj1.git

If it does not exist yet, use git remote add origin <url>.

Source: tasks.md · Tags: remote, origin, set-url, ssh url, push, fetch · Link
Remote & SyncfaqClone timeout because SSH tried port 22Why did git clone user@host:path fail on port 22?

The scp-style syntax defaults to SSH port 22. If the server listens on 2222, use:

git clone ssh://intel145@209.182.212.74:2222/home/intel145/websites/gitrepo/git.git git

Or define port 2222 in ~/.ssh/config.

Source: Session Q&A · Tags: clone, port 22, port 2222, timeout, ssh · Link
Remote & SyncfaqCorrect SSH remote syntax with port 2222What was wrong with git remote add origin ssh -p 2222 user@host -i key?

git remote add accepts a remote name and one URL. SSH options such as -p and -i are not separate Git remote arguments. Use:

git remote add origin ssh://intel145@209.182.212.74:2222/home/intel145/websites/gitrepo/proj1.git

Configure the identity file in ~/.ssh/config or use GIT_SSH_COMMAND when needed.

Source: Session Q&A · Tags: remote add, ssh, port, 2222, identity file, url · Link
Remote & SynccheatList actual branches and tags on the remoteHow do I inspect remote branches without guessing?
git ls-remote --heads origin
git ls-remote --tags origin

This queries the remote directly. git branch -r shows locally cached remote-tracking refs after a fetch.

Source: Session Q&A · Tags: ls-remote, remote branches, tags, refs · Link
Remote & SyncglossaryMeaning of git remote add originWhat does git remote add origin mean?

The command stores a named connection from the local working copy to another repository:

git remote add origin <url>

origin is a conventional nickname. git push origin main means push local main to the repository named origin.

Source: Session Q&A · Tags: origin, remote add, alias, url · Link
Remote & SynctutorialPull latest files from remote mainHow do I get current remote files before starting work?

From a clean working copy:

git fetch origin
git checkout main
git pull

If your remote is named git rather than origin, replace the name in the command.

Source: tasks.md · Tags: pull, fetch, main, latest, sync, remote · Link
Remote & SyncfaqRemote already existsWhat do I do when Git says remote git already exists?

Do not run git remote add again. Inspect the existing remote:

git remote -v

Then repair it, for example:

git remote set-url git /home/intel145/websites/gitrepo/git.git

Or replace that local path with the correct SSH URL.

Source: Session Q&A · Tags: remote exists, set-url, origin, git · Link
Remote & SynctutorialUse a local filesystem path as a remoteHow do I use a repository on the same machine as a remote?

A local bare repository can be used as a remote by path:

git remote add origin /home/intel145/websites/gitrepo/proj1.git
git push -u origin main

file:///home/intel145/.../proj1.git also works.

Source: Session Q&A · Tags: local remote, file, bare repository, path · Link
WorkflowstutorialClone proj1 into a separate proj1fix folderHow do I get latest proj1 into dev/proj1fix, edit it, and send changes back?
mkdir -p ~/dev
cd ~/dev
git clone ssh://intel145@209.182.212.74:2222/home/intel145/websites/gitrepo/proj1.git proj1fix
cd proj1fix

Then edit, test, commit, and push:

git add -A
git commit -m 'Fix description'
git push origin main
Source: git.cheatsheet.md · Tags: proj1, proj1fix, clone, fix, push · Link
WorkflowstutorialCreate and publish the first v1 releaseHow do I update project files, create v1, tag it, and update the repository?

After editing and testing:

git add -A
git commit -m 'Complete v1 work'
./git-bump-version 1.0.0
git push origin main
git push origin --tags

The helper creates tag v1.0.0. If desired, create a short alias tag too:

git tag -a v1 -m 'Release v1'
git push origin v1
Source: git.cheatsheet.md · Tags: v1, first release, tag, VERSION, push · Link
WorkflowstutorialCreate proj1, its central bare repo, and publish first commitHow do I create a new dev project and repository?

On a development machine:

mkdir -p ~/projects/proj1
cd ~/projects/proj1
git init -b main
echo '# proj1' > README.md
git add README.md
git commit -m 'Initial commit'

On the Linux server:

mkdir -p /home/intel145/websites/gitrepo
git init --bare /home/intel145/websites/gitrepo/proj1.git

Back in the working copy:

git remote add origin ssh://intel145@209.182.212.74:2222/home/intel145/websites/gitrepo/proj1.git
git push -u origin main
Source: git.cheatsheet.md · Tags: new project, proj1, init, bare repo, initial push · Link
WorkflowstaskRequirements for a simple pull scriptCan a pull script always fetch current files from the same SSH server?

A pull helper still needs a configured remote and working SSH access. The reliable core is:

git checkout main
git pull origin main

A script may use a fixed remote name, but it cannot bypass the remote URL, SSH setup, or uncommitted-change checks.

Source: Session Q&A · Tags: script, pull, ssh, remote, main · Link
WorkflowstutorialUse macOS and Linux working copies with one server repositoryIs it correct to develop on macOS and Linux against one central repo?

Yes. Each machine has its own working copy; the Linux bare repository is the shared central storage. On whichever machine you begin work, first pull main. Edit, test, commit, tag a release when ready, and push. On the other machine, pull before starting more work.

Source: faq2.md · Tags: macos, linux, two environments, central repo, sync · Link
Versions & TagscheatCheck current project version and release stateHow do I tell what project version or tag I have?
cat VERSION
git describe --tags --always
git status

An exact tag such as v2.1.0 with a clean working tree indicates a released state. v2.1.0-3-gabcd123 means three commits past that tag.

Source: faq3.md · Tags: VERSION, describe, tag, current version, status · Link
Versions & TagstutorialMake changes and release v3.0.0How do I get current files, make changes, make v3.0.0, and update the server?
git checkout main
git pull
# edit and test files
git add -A
git commit -m 'Implement v3 features'
./git-bump-version 3.0.0
git push origin main
git push origin --tags

The script updates VERSION, commits it, and creates v3.0.0.

Source: faq4.md · Tags: release, v3.0.0, VERSION, tag, push, workflow · Link
Versions & TagscheatRun git-bump-version in a working copyWhy did git-bump-version fail when used against git.git?

Run it in a normal working copy, not in a bare *.git folder:

cd /home/intel145/websites/apps/git
./git-bump-version 2.0.0

A bare repo has no work tree, so git add and git commit cannot run there.

Source: Session Q&A · Tags: git-bump-version, working tree, bare repo, current directory · Link
Versions & TagsglossaryUse MAJOR.MINOR.PATCH versionsWhy should I use 2.0.0 instead of 2.0?

Use three numeric parts: MAJOR.MINOR.PATCH. Examples: 1.0.0, 2.0.0, 2.1.0, 2.1.1.

  • Major: breaking changes
  • Minor: backwards-compatible features
  • Patch: backwards-compatible fixes

The supplied bump script expects this three-part form when auto-incrementing.

Source: Session Q&A · Tags: semantic version, semver, major, minor, patch · Link
Versions & TagsfaqWhat git-bump-version changesDoes the version script add a version and filename into every file?

The normal version script changes only the root VERSION file, commits it, and creates a release tag. It does not add filename or version headers to every source file.

This avoids noisy diffs. Prefer VERSION as the single source of truth, or generate one version config file during build/deploy.

Source: Session Q&A · Tags: bump version, VERSION, headers, all files, script · Link
Versions & TagsfaqWhen to use tagsWhen should I use tags?

Use tags to mark fixed release or milestone commits such as v1.0.0, v2.0.0, and v2.1.0. A branch is for ongoing development; a tag is a named snapshot that should normally remain unchanged.

git tag -a v2.0.0 -m 'Release v2.0.0'
git push origin --tags
Source: faq1.md · Tags: tag, release, version, milestone, v1, v2 · Link
BranchescheatList local, remote, and all branchesHow do I list branches?
git branch       # local branches
git branch -r    # remote-tracking branches
git branch -a    # local and remote-tracking branches

Use git fetch origin --prune first if you need fresh remote branch information.

Source: Session Q&A · Tags: branch, list, local, remote, all · Link
BranchestutorialMaintain v2 while developing v3When do I need a version branch such as 2.x?

Create long-lived maintenance branches only when two major versions need simultaneous support:

git checkout v2.0.0
git checkout -b 2.x
git push -u origin 2.x

Make v2 fixes on 2.x, tag them as v2.0.1, and continue v3 work on main.

Source: faq1.md · Tags: 2.x, 3.x, maintenance, hotfix, parallel versions · Link
BranchestutorialModify a file based on old v1.1How do I modify v1.1 of README.md and commit back?

Do not modify a published tag. Make a branch starting from it:

git checkout v1.1
git checkout -b fix/readme-from-v1.1
vi README.md
git add README.md
git commit -m 'Update README based on v1.1'

Tag a follow-up release such as v1.1.1, then push the branch and tag.

Source: Session Q&A · Tags: old tag, v1.1, README.md, branch, hotfix · Link
BranchescheatShow the current branchHow do I check which branch I am currently on?
git branch --show-current

Alternatives: git branch, git rev-parse --abbrev-ref HEAD, or git status. git branch marks the current branch with *.

Source: Session Q&A · Tags: current branch, show current, HEAD · Link
BranchescheatShow tracking remote branchHow do I check the remote tracking branch for the current branch?
git rev-parse --abbrev-ref --symbolic-full-name @{u}

Example output: origin/main. To see upstreams for all local branches:

git branch -vv
Source: Session Q&A · Tags: upstream, tracking, origin/main, remote branch · Link
BranchesfaqWhen to create a new branchWhen do I change to a new branch?

For one active release line, stay on main and use tags for v1, v2, v3, and so on. Create a branch for isolated feature work, experiments, a risky refactor, or maintenance on an older release.

git checkout main
git pull
git checkout -b feature/new-auth
Source: faq3.md · Tags: branch, feature, experiment, main, maintenance · Link
Files & HistoryfaqAdd selected files and ignore files/foldersHow do I git add a list of files and ignore files or folders?

Stage selected files:

git add README.md VERSION src/main.php

Example .gitignore:

*.log
tmp/
.DS_Store
.env
junk
old/

To stop tracking an already tracked file but retain it locally:

git rm --cached junk
echo 'junk' >> .gitignore
git add .gitignore
Source: faq5.md · Tags: git add, gitignore, ignore, folder, stage, untrack · Link
Files & HistorycheatCheck file dates, sizes, and largest history objectsHow do I inspect repository files, dates, sizes, and versions?

Last change date for one file:

git log -1 --format='%ad' --date=short -- README.md

Sizes of tracked working-tree files:

git ls-files | xargs ls -lSh

Largest objects ever committed:

git rev-list --objects --all | \
  git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' | \
  sed -n 's/^blob //p' | sort -k2 -nr | head -n 20
Source: faq1.md · Tags: sizes, dates, largest files, history, stat · Link
Files & HistorycheatCompare README.md between v1 and v2How do I compare README.md in v1 versus v2?
git --no-pager diff v1 v2 -- README.md

Use full tag names such as v1.0.0 and v2.0.0 if that is how your tags are named.

Source: Session Q&A · Tags: diff, README.md, v1, v2, compare · Link
Files & HistorycheatCompare current file to last commitHow do I see unstaged or staged README changes?

Unstaged changes:

git diff -- README.md

Staged changes:

git diff --cached -- README.md

Working file versus last commit:

git diff HEAD -- README.md
Source: Session Q&A · Tags: diff, working tree, staged, cached, README · Link
Files & HistorycheatDisable Git pager (more/less)How do I stop Git from using more or less?

For one command:

git --no-pager diff v1 v2 -- README.md

Disable paging for diffs globally:

git config --global pager.diff false

Or avoid paging for short output:

git config --global core.pager 'less -F -X'
Source: Session Q&A · Tags: pager, more, less, no-pager, diff · Link
Files & HistorycheatList all tracked files in current versionHow do I list all files in proj1?
git ls-files

Or list files in the current commit:

git ls-tree -r HEAD --name-only
Source: Session Q&A · Tags: list files, ls-files, ls-tree, tracked · Link
Files & HistorytutorialList and export all tagged versions of one fileHow do I see what versions of a file exist and get each version?
mkdir -p versions
for tag in $(git tag -l 'v*' | sort -V); do
  git show "$tag:README.md" > "versions/README.$tag.md"
done

If a tag predates the file, git show will fail for that tag; that is expected.

Source: Session Q&A · Tags: file versions, export, tags, show, README.md · Link
Files & HistorycheatList edited, staged, and untracked filesHow do I see files being edited or checked out?
git status

It groups files into staged changes, unstaged changes, and untracked files. Use it before committing, pulling, or pushing.

Source: Session Q&A · Tags: status, modified, staged, untracked, files · Link
Files & HistorycheatRestore one file from an older versionHow do I put README.md from v1 into my current working copy?
git checkout v1 -- README.md

This replaces and stages README.md. Review using git diff --cached, then commit if intended.

Source: Session Q&A · Tags: restore, checkout, old version, README.md, v1 · Link
Files & HistorycheatSee commit history of one fileHow do I see what versions of a file exist?
git log --decorate --oneline -- README.md

For actual patches:

git log --decorate -p -- README.md
Source: Session Q&A · Tags: history, file versions, log, README.md, commits · Link
Files & HistorycheatView or save README.md from v1How do I get v1 of README.md without changing current files?

View:

git show v1:README.md

Save separately:

git show v1:README.md > README.v1.md

This does not alter the current working copy.

Source: Session Q&A · Tags: show, old version, README.md, tag, export · Link
Files & HistoryfaqWhy git describe fails when given README.mdWhy does git describe --tags --always -- README.md say not a valid object name?

git describe accepts commits or refs, not file paths. Use:

git describe --tags --always

For a file's history use git log --decorate --oneline -- README.md; for file content at a tag use git show v1:README.md.