Version Control - git

Q-66: How should multiple programmers work on the same file at the same time?





Setup

  1. Install Git Here (Required): http://git-scm.com/downloads
  2. If you want a GUI (optional) : http://git-scm.com/downloads/guis
  3. Use git bash if you are on windows.

Presentation

Follow along with your own computer!

Demo

We’re going to now work as a groups. Find two other people and practice commiting, pushing, and pulling.

Commands

  1. git add – adds a file to the tracked files and stages it for commit

    1. Common use - git add “file.py” or git add * (To add everything)
  2. git status – shows you the current status of your repository (like changed / added / deleted files)

  3. git log – shows you the n last commit messages with some other data

  4. git commit – it will “save” current state of files locally, and prepare them for git push

    1. Common use - git commit -m ‘Commit Message’ or git commit -am ‘Commit Messge’
  5. git push – it will collect all of your current commits that havent been commited and push them to remote repository

    1. Common use - Git push origin master
  6. git pull – combination of git fetch and git merge

    1. Common use - Git pull origin master
  7. git fetch – it fetches the remote changes to your local repository, but it doesn’t change your current source contents

  8. git merge – it’s used for merging 2 branches into one, if theres no need for 2 anymore

  9. git branch <new-branch-name> – creates a branch with name “new-branch-name”

  10. git diff – if you fetch the changes from remote, you can then see the difference between your code current version and last one on remote

A cheat sheet