Git


Git // version contol software
Bitbucket, GitHub // Git hosts
SourceTree, GitKraken // Git clients

// Git version
git --version

// open and show the location of the global config file
git config --global --edit

// create a new local repository
git init

// connect a local repository to a remote repository
git remote add origin username@host:/path/to/repository

// create a local repository from a remote repository (starting with the remote default branch)
git clone username@host:/path/to/repository

// list of remote servers configured for a local repository
git remote -v

// stage a specific file
git add test.txt

// stage all files (new and modified)
git add .

// list of files that have changed (ready to be staged/committed)
git status

// commit files to local repository
git commit -m "initial commit"

// send changes to the remote repository... assumes a remote repo is defined (see git remote -v)
git push

// create a new branch
git branch myNewBranch

// create a new branch and switch to it
git checkout -b myNewBranch

// switch from one branch to another
git checkout myOtherBranch

// list of branches in your local repository (current branch noted)
git branch

// delete a branch in your local repository
git branch -d myBranch

// fetch and merge changes from the remote repository to your local repository
git pull

// merge a branch into your active branch
git merge myBranch

// revert a file that has been modified but not staged
git checkout -- test.txt

// unstage a file
git reset HEAD test.txt

// revert to the last commit in the local repo (last commit from latest pull or last local commit, if any)
git reset --hard

// revert to a specific commit in the local repo (any commits from latest pull or local commits, if any)
git reset --hard <commit hash> // use git log to find the specific commit hash

// display one-line view of the last 5 commits (with abbreviated commit hash)
git log --oneline -5

// display one-line view of the last 5 commits (with full commit hash)
git log --pretty=oneline -5

// display one-line view of the commits in develop which are not in qa
git log qa..develop --oneline