Skip to content

Instantly share code, notes, and snippets.

@powerc9000
Last active December 18, 2015 10:39
Show Gist options
  • Save powerc9000/5769891 to your computer and use it in GitHub Desktop.
Save powerc9000/5769891 to your computer and use it in GitHub Desktop.
My git presentation

Link to this (so meta): https://gist.github.com/powerc9000/5769891

Why

All the cool kids are doing it!

and

Git helps us colaborate easier and manage the codebase.

Installing Git

First open your terminal and type in the command git if it works then you can stare off into the distance for a while. If it doesnt work navigate yourself to http://git-scm.com/ download the file and install it. Open a new terminal after it finished the install and try running git. if it doesnt work I'm sorry, Cry or something.

Command Line

First off we want to learn a few commands in terminal. ~ refers to your home folder. located at /users/yourusername cd Means change directory you can do relative or absolute paths if I am in ~ and I cd Sites cd will look for a directory called sites in our current directory. ls I thin it stands for list. It lists all the files and folders in the current directory.

Git from the git-go (hahaha)

git init initializes git in the directory you are currently in and makes an empty repository (whether or not files exist in the folder)

Git tracks a folder you initialize it in it keeps track of what files changed and the history of file changes. When you make a change to a file you need to tell git you want it to stage that file and easy way to stage all changed files is git add .

After you make changes and have staged the changes you made you now want to commit the changes you made git commit -m"commit message here". Commits record changes that you've made. The nice thing about commits is you can revert them. So if you delete a file or something you can get it back from the abyss this can be super handy. -m in git commit is important it is a commit message and you should try to be concise but say what changes you made.

git branch allows you to branch out your code. The defualt branch is master. So say you have working code but you want to do something funky but dont want to break the working code you do git branch <branchName> and then git checkout <branchName> now you are in the new branch. if you want to switch back git checkout <oldbranch> if you want to switch to the new one after you made it git checkout <branchName>. A good practice it to write all your code in a different branch then master and then when your code works merge it back in.

When you want to share your code with someone else you use git push <remote> <branch> The tool we use to share code it github but it doesnt totally have to be. This command will push the changes in the branch you name to the remote you name. When you push your code someone else can pull it and start to use it. How rad!

git pull <remote> <branch> allows you to pull changes from a remote and merge them into your files. git pull will merge the branch you name into your current branch so be careful.

Git and Github

First off Github needs to verify you it does this with RSA so we need to make a key. Go to https://help.github.com/articles/generating-ssh-keys and follow thos instructions to get that stuff setup.

Say someone already has made the repo but we dont have it locally we can just clone the repo to our local machine and work on the code! git clone <remoteUrl> allows us to do just that. If you go to the repo on Github and click on the button that says ssh copy that url and use that with git clone. NOTE: git clone will make a new directory with the name of the repo in the directory you are in. so if you need to add the repo to your site folder just cd to ~/Sites and running git clone <remoteUrl> will make a folder for you. How nice.

Best practices and rules

  • I am master on the repos. So if something needs doing or repo needs making. Talk to me.
  • Branches are cheap. Branches are good. Use them.
  • Have fun.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment