Getting Started with Git

Questions? Get IT help

GitG=Hub offers a nice start-up guide for Git

A few Git GUI clients

MysysgitGUI Windows client
SourceTreeFree GIT GUI client for Windows and Mac
TowerCommercial GUI client for Mac
GitKrakenFree GIT GUI Client for Mac, Windows and Linux

Recommended Git documentation

Getting started: Cloning the current Main or Master branch 

Make a directory for all your Git projects

  1. Example c:dev/git-projects

          Open the Git command line client

  1. Change directory to the git-projects directory

    Example: cd  /c/dev/git-projects

  2. Clone the existing repository to your local machine

    Example  git clone [email protected]:ucsfp1.git

  3. Set up your own branch for changes

    git checkout -b mybranch

Daily work flow

  1. Synch your local main repository to the remote main
     git pull
  2. Add your changes to your local repository in 
    git add /docroot/sites/yoursites.ucsf.edu
  3. Commit your changes
    The git commit command adds you changes to the current local version of the branch.
    git commit -m "my change message goes here"
  4. Merging your feature branch change to the remote main branch
    1. Check what branch you are in
      git status
    2. Check out the local main branch
      git checkout main
    3. Merge your changes into the local main branch
      git merge mybranch
    4. Push your changes into the remote main branch
      git push origin master

For when "something goes wrong"

Checking  When a File was Last Changed and by Whom

git log filename

Removing a Directory Full of Files

git rm -r bad_directory/

Justin Hileman wrote a blog post and created a visualization called "Git Pretty". The visualization is handy for navigating out of weird Git situations/messes that happen occasionally. The blog is gone, but the visualization lives on. Here's a recreation of it in Mermaid.js.

Resetting your local repository

git fetch origin

git reset --hard origin/master

Git "other"

A more readable git log of commits

alias gitp='git log --graph --pretty=format:'"'"'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'"'"' --abbrev-commit'