# Overiew of `Git` - OS version control tool - audit trail: who modified what and when - enables accountability - allows devs to check out and work on code segments that are then committed and merged into project - Git terminology - repository: sub-directory structure containing project files - staged files: files within a repo that are ready to be committed to the repo for change tracking - branch: separate version of a repo; once changes are complete, the branch can be merged back into the main project - clone: synchronized copy of a repo - fork: standalone copy of a repo - often pre-installed in newer linux distros - GitHub is a website with a collection of tools that integrate with Git # Config Commands - `git --version` confirms that git is installed and shows version - `git help --all` shows listing of available git commands - `git help commit` shows help associated with commit command - `git config --global user.name "xxx"` adds user - `git config --global user.email "xxx"` adds email address - `git config --list` shows config related info that has been specified such as user.name and user.email - pulls from `~/.gitconfig` # Initialization & Commits - General flow: - `git init` creates new repo - `git add` adds files to index (staging area) - `git commit` adds files in index to local repo - `git push` pushes local repo to remote repo - `git init` initializes local version control for current directory - creates `.git` directory within current directory - `git tag` shows tag info for repo - `git tag -a v1.0 -m "sample details"` adds v1.0 tag to repo with message - `git status` shows version control info for repo - `.gitignore` notes that `*.log` files should not be tracked - `git add file_name` tracks changes to file by adding to index - `git commit -m "this is ver 1.0"` with a message added to commit edit message file - the commit edit message file will not be automatically opened in nano here because the -m flag was added - `git log` shows usage/time of command line git commands - `git clone --help` shows syntax associated with clone command - no authentication necessary for public repos - `git clone https://github.org/johnpapa/node-hello.git` clones node-hello repo to current directory # Branching - `git branch --list` shows branch info if current directory is a repo - `git branch new-branch` creates new branch/snapshot of repo in current directory - `git branch -m new_name` to rename currently selected branch - `git checkout new-branch` switches to new-branch branch of repo - `git add newfile.txt` adds/stages new uncommited file to repo - `git commit` automatically opens commit edit message file, then commits after closing commit edit message ![[images/git-commit-message.png]]![[images/git-commit.png]] - stop commit edit message file from opening by issuing commit command with -m flag: `git commit -m "details"` - `git merge new-branch` merges new-branch into master ![[images/git-merge.png]]