A work in progress intended for my own reference, but if this proves helpful to others as well that’s great.
Create a repo
Clone a repo
# clone the repo as a new folder in the current directory
$ git clone <url of repo>
Code language: PHP (php)
Create a repo
# create git repo
$ git init
Code language: PHP (php)
Don’t forget to setup your .gitignore file before adding all the files.
# add all files to the repo
$ git add .
# add a single file
$ git add <file name>
Code language: PHP (php)
Working with a repo
Commit, push and pull
# commit local changes
$ git commit -m "comment goes here"
# push changes to remote repo
$ git push
# pull changes from remote repo
$ git pull
Code language: PHP (php)
Roll back commits
# HEAD~number of commits
# soft keeps changes but drops commits
git reset --soft HEAD~1
# hard drops commits and any changes
git reset —hard HEAD~1
Code language: PHP (php)
Remote Repo
List remote branches
list remote
$ git branch -r
list local and remote
$ git branch -a
Code language: PHP (php)
Pull remote branch
if the branch exist on server but not locally
$ git switch <NAME OF BRANCH>
Code language: HTML, XML (xml)
# or
git fetch origin; git checkout --track origin/branchName
Code language: PHP (php)
Push remote branch
git push -u origin branchName
Delete remote branch
git push origin --delete branchName
Code language: JavaScript (javascript)
Other helpful stuff
Configure profile
Setting this up will tell people that you did your work.
# omit your name/email and git will return the current setting
$ git config --global user.name "Clint Vidler"
$ git config --global user.email address@example.com
Code language: PHP (php)
Get help
# learn about a command
$ git help
$ git help [command]
# enter 'q' to quit the help document
Code language: PHP (php)
Get info about repo
# obtain the status of the local repo
$ git status
# for just a summary
$ git status -s
Code language: PHP (php)
# obtain a log of commits
$ git log
Code language: PHP (php)
# show a list of all tracked files and folders
git ls-tree -r main --name-only
Code language: PHP (php)
# show files that were changed in the last commit
git diff --name-only HEAD~0 HEAD~1
Code language: PHP (php)
GUI displaying changes
$ gitk