GIT_MANUAL
VERSION_CONTROL_PROTOCOLS
SETUP & INIT
git init
Initialize a new local repository in the current directory.
git clone [url]
Download a project and its entire version history.
STAGING & COMMIT
git add [file]
Snapshot a file in preparation for versioning (use . for all).
git commit -m "[msg]"
Record file snapshots permanently in version history.
git status
List all new or modified files to be committed.
BRANCHING
git branch
List all local branches in the current repository.
git checkout -b [name]
Create a new branch and switch to it immediately.
git merge [branch]
Combine the specified branch’s history into the current branch.
SYNCING
git pull
Fetch and merge changes on the remote server to your working directory.
git push
Upload local repository content to a remote repository.
git fetch
Download objects and refs from another repository without merging.
SSH REMOTE ACCESS
ssh-keygen -t ed25519 -C "[email protected]"
Generate a new SSH key pair for secure authentication.
eval "$(ssh-agent -s)" && ssh-add ~/.ssh/id_ed25519
Start the ssh-agent in the background and add your private key.
git remote set-url origin [email protected]:User/repo.git
Change your repository's remote URL from HTTPS to SSH.
Host my-alias
HostName github.com
IdentityFile ~/.ssh/id_custom
Add to ~/.ssh/config to map a host alias to a specific key for multi-key setups.
git remote set-url origin git@my-alias:User/repo.git
Use your config alias in the remote URL. git pull will now automatically use the correct key!
HISTORY & UNDO
git log
Show the commit history for the currently active branch.
git reset [commit]
Undo all commits after [commit], preserving changes locally.
git revert [commit]
Create a new commit that undoes all of the changes made in [commit].