Skip to content

Git Cheat Sheet

Andy Berry edited this page Dec 3, 2013 · 5 revisions

Getting Started

  • clone the repo to your local machine

    • git clone <URL>
    • The URL for the repo is found on the GitHub page
  • change to the develop branch

    • git checkout develop
  • set up submodules

    • git submodule init
    • git submodule update
    • when changing branches you might need to run git submodule update again if submodules have changed
  • make some changes to files

  • check the status

    • git status
    • This should point out there are untracked files, or that some files have changed and need to be staged
  • use diff to check your staging what you want

    • git diff file1 or git diff to show all changes
  • stage the files

    • git add file1
    • git add file2
    • This can also be done on a directory level, or add all with git add -A
  • check the status again

    • You should see the files are now ready for a commit
  • commit

    • git commit -m “i made some awesome changes”
  • rinse and repeat

  • push changes

    • git push origin develop

Feature branching

  • clone the repo and switch to the develop branch
  • create your branch
    • git branch featureX
    • No need for the ‘-t’ here since we’re branching from a remote branch
  • push the new branch so other people can see it/make changes
    • git push origin featureX
  • make some commits and push every so often
  • merge from develop to the feature branch
    • git merge develop
  • Use a pull-request to merge the feature back in to develop

Releasing

  • This should all be do-able through the GitHub interface via a pull-request
  • The resulting commit should be tagged to set the version

Other Commands

  • View your remotes (external locations)
    • git remote -v
    • In general you will only have 1
    • Its best to keep GitHub as ‘origin’
  • View the branches, including remote ones
    • git branch -a
  • Remove all untracked files (files created and not in source control)
    • git clean -d -f
  • View a log of commits
    • git log
  • The number one command
    • git help or git help <something>

More Useful Stuff

Clone this wiki locally