GIT Commands
The following is a reference and examples of some GIT commands commonly used. This can serve as a cheat sheet.
Set Remote
Set the repository used for push and pull - the remote. Normally the remote is "origin", but this can be confirmed in the ".git/config" file.git remote set-url origin https://you.domain/repo
List Branches
git branch -a
Restore Files From “.git” Folder
git reset --hard HEAD
Change Branch
git checkout BRANCH
Create Branch
git branch BRANCH
Delete Branch
git branch -d BRANCH
Force Delete Branch
git branch -D BRANCH
Merge Branch
We will switch to the branch we want to merg INTO - the target. So if we are going from branch into master, check out master, then merge. Note that the “--no-ff” option will preserve the branch in the history so it’s not linear (preferred as we can see what was done).git checkout TARGETBRANCH git merge --no-ff SOURCEBRANCH git push
Roll Repo Back to Prior Commit
git checkout COMMIT_SHA
Roll Repo to Current Latest Commit
git checkout master