Git CLI reference

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>

Create a repo

# create git repo
$ git init

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>

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

Remote Repo

List remote branches

list remote
$ git branch -r
list local and remote
$ git branch -a

Pull remote branch

if the branch exist on server but not locally
$ git switch <NAME OF BRANCH>

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 "Clint Vidler"
$ git config --global

Get help

# learn about a command
$ git help
$ git help [command]
# enter 'q' to quit the help document

Get info about repo

# obtain the status of the local repo
$ git status
# for just a summary
$ git status -s
# obtain a log of commits
$ git log
# show a list of all tracked files and folders
git ls-tree -r master --name-only

GUI displaying changes

$ gitk

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.