Git is a tool that is used to:
- keeping track of your files
- keeping track of changes in your files
- backup in case something breaks
In order to work with Git you need to open terminal.
Then go into the directory which contains your files.
git init <-- this command tells the computer you want to work in git. It starts git in the directory you are in.
git add . <--- this command adds everything in that directory to the staging area the . is a shortcut that means current folder and all files in it.
get commit –quiet -m “WHOA THIS IS MY FIRST COMMIT. WICKED.” <--This solidifies the changes in the staging area into the repository the -m is called a flag, it tells git you are going to send some special data
The staging area is important because:
git status <--shows current status of your working directory
Branching
Branching encourages a few things
-
Frictionless Context Switching
You can work on different changes in your code by setting up a separate branch for each change -
Feature Based Workflow
Allow you to create new features without affecting the the existing site -
Disposable Experimentation
try to see if something works without breaking main site. Your branch is in its own sandbox and site is protected and safe.
git branch branchname <-- creates a new branch named branchname git checkout branchname <-- sets working tree to branch named branchname git checkout master <-- to go out of branch you are in back to master git checkout -b branchname <-- a shortcut to create a branch and switch into the branch immediately
To Merge a Branch into Master
git checkout master <-- change back to the master git merge branchname <--merges committed changes made in branchname with current branch
Repositories
Bitbucket <--use for private repositories because it is free! Github <--use for public repositories Think of a repository as an exact duplicate of your working tree but stored elsewhere. You push all of your changes to that repository to keep track of it for other people to then pull down and modify later. git push <-- Pushes changes on your local computer to your repository on git hub or bitbucket git pull <-- to pull changes other developers have made to the git hub or bitbucket repository to your local computer git clone <--to duplicate a repository to your local computer for example: git clone --recursive git@github.com:markjaquit/WordPress-Skeleton.git
Submodules
Submodules allow you to keep separate sections of your code under source control (repos within repos)
git submodule add repository path/to/location <--Adds submodule located at repository to path/to/location within project
.gitignore
use .gitignore to prevent files from being added to the repo
cat .gitignore <--lists the files that are being ignored
Strategy
-
commit early, commit often the more points you will have to roll back to in case something breaks or someone screws something up
-
use decriptive commit messages to understand what you did
-
master branch is for stable only
-
branch naming: initials of developer/feature-name
Working with multiple devs
git rebase branchname
updates the current branch with changes made in another
Resources: http://bit.ly/WhatTheGit
Leave a Reply