Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Basic Git Commands

Basic Git Commands

Nina R's presentation from Oct. 11, 2011! She covered common every day Git commands, and ends with a list of resources.

womenwhocode

October 19, 2011
Tweet

More Decks by womenwhocode

Other Decks in Technology

Transcript

  1. Why GIT? Git is a version control system! It allows

    you to store your changes! Github allows you to store your changes remotely. GIT stores the file content in BLOBs (binary large objects). The folders are represented as trees. https://github.com/images/error/octocat_happy.gif
  2. GIT commands 1 • git init ◦ to initialize local

    repo • git status ◦ to check what files changed from the last commit • git diff (--cached) ◦ to see what was changed from last commit (if you did add already) • git add . ◦ to add all changed files to commit • git add <file1> ◦ to add file with name 'file1' to commit • git commit -m <"My commit msg"> ◦ to add changes to your local history • git log ◦ to see the history of your project
  3. When working on the remote repository... 1. Make sure your

    ssh keys are set up, and global user is set too. http://help.github.com/mac-set-up-git/ 2. git clone <[email protected]:username/RepositoryName.git> - to create a copy of remote repository on your local machine http://help.github.com/fork-a-repo/
  4. GIT commands 2 • git branch ◦ check list of

    branches and on which you are currently on • git checkout <branch-name> ◦ switch to the branch called 'branch-name' • git checkout -b <branch-name> ◦ create&checkout a new branch called 'branch-name' off the branch on which you are currently on • git fetch ◦ download new branches and data from remote repo • git push origin <branch-name> ◦ push your branch and data to remote repo • git pull origin <branch-name> ◦ fetch from remote repo and try to merge into current branch
  5. GIT commands 3 • git merge <branch-name> ◦ merges 'branch-name'

    branch into the current branch Usually there are conflicts that need to be resolved: Solving them: Then: git add file.txt and git commit -m "Solved conflict" • git reset --hard HEAD ◦ reverts to pre-merged state if you haven't committed ◦ use ORIG_HEAD if you committed merge and want to throw it away http://book.git-scm.com/3_basic_branching_and_merging.html Alternative to merging is rebasing.
  6. GIT commands 4 Using SHA, you can: • git diff

    <SHA> ◦ compare you current changes to what one of the previous commits • git show <SHA> ◦ see details about that commit • git tag <tagname> <SHA> ◦ give your own name to commit There are more complicated and dangerous commands that utilize SHA, like git revert and git reset.
  7. Useful Resources - Git cheat sheet: http://byte.kde.org/~zrusin/git/git-cheat-sheet-medium.png - Git documentation:

    http://git-scm.com/documentation - Git screencasts: http://gitcasts.com/ - Everyday Git with 20 Commands: http://schacon.github.com/git/everyday.html - Another Git tutorial: http://excess.org/article/2008/07/ogre-git-tutorial/