A high-level overview of my most used git features.
Written by Anthony Ongaro, on 2023-1-20
Bold is definition, inline code is terminal command related.
General terms
Terminal… terms
git a version control system used in software developmentHEAD is the most recent commitorigin is the codebase to ‘trust’ the most (remote, probably on Github)remote references your remote repository (probably Github)branch is the current working branch of the git treeInitialize a new local repository, stage your files, and start committing them
git init initializes a new local git repository in the current working directorygit add <filename> adds file to the staging areagit reset removes all files from staging areagit commit -m '<commit message>' new commit, use syntax “This commit will…” for msgWork more effectively with coworkers by creating a branch before making changes to a shared repository. This tracks changes under a ‘branch’ that can then be merged with the main via a pull request
git branch <new branch_name> create a new git branchgit branch -d <branch_name> safely deletes branch assuming mergedgit checkout <branch_name> moves to <branch_name> branchgit checkout -b <branch_name> does both of the above, combinedgit checkout - takes you to last branch you were working ongit rebase main to move your branch’s history up to main’s HEADgit rebase main --interactive to select which commits to squash replaces pickgit merge <branch_name> to merge branch you’re ON (main?) with <branch_name>git status checks current status of staging areagit diff shows difference betweengit log shows log of project’s commits use --graph --oneline to simplifygit remote -v shows current remote repository connectiongit remote add origin <ssh address> connect initialized local repo to a Github repositorygit clone <ssh address> creates a new project folder locally with git init’d to remotegit push -u origin <branch_name> push last commit to remote, all future pushes can use:git push push to remote once set up with abovegit pull pull down latest changes from Github repositoryFix your messed up commit messages or files forgotten from last commit
git commit --amend opens text editor to modify last commit messagegit commit --amend -m '<commit_message>' updates most recent commit to <commit_message>git add <file> then git commit --amend --no-edit adds forgotten file to last commitgit reset <commit_id> leaves files ‘as-is’ but un-commits last commitgit reset --hard <commit_id> deletes last commit and all changes since When you are writing code but doesn’t work yet, and you want to save for later without committing your work to the official history
git stash saves your changes since last commit for later in an arraygit stash pop brings back your most recent stash from end of arraygit stash save <name> save a stash with a specific namegit stash list list all available stashes by namegit stash apply <index_num> brings back stash at index position <index_num>You can do custom key bindings using aliases