git training




SVN to git

Part One - Basic Commands



Install git

Github's writeup on how to install for Mac:

Windows installation with CYGWIN:
* Defer to Troy *

Checking out a git repository

git clone  is similar to  svn checkout

Run the command:
git clone https://github.com/mmgyglobal/WWI.git wwi


This creates a local copy of the git repository. 

The clone URL can be found on Github. 


MMGY's GitHub Organization:

https://github.com/mmgyglobal/

Adding files

Add files in individually
git add path/to/file

Add all files at once

git add .


Removing files

Remove files individually:
git rm path/to/file

Remove files recursively:

git rm directory/ -r


GIT STATUS

Return the current status of local copy:
git status

Will return what files haven't been added to the repository and local changes that haven't been committed.

GIT commit

Commit command:

git commit -a -m "Commit message goes here"

This command records a "snapshot" of the local tracked changes and keeps the records locally. 


This will NOT push changes to the remote repository.

DON'T BE AFRAID OF COMMITMENT

Commit often and commit early.


When working on feature requests (separate branches) - commit as often as possible to make merging as
painless as possible later on down the road.


Also try and provide meaningful commit messages.

GIT PUSH

Run this command
git push origin master

This pushes all local commits out to the remote repository. Origin is the repo destination and master is the branch.


GIT COmmand line is good

But GUI can be just as good...
Some other options you can use 
besides command line:

GitHub's Tool:
SmartGit:

Tower (Mac Only):

GIT TRAINING




SVN TO GIT

Part Two - Branching/Merging

Create new branch

Command to create a new branch:
git branch about-section

This creates a new branch called "about-section".


Each branch name should be meaningful to the feature enhancement that is being worked on.

View git branches

Command to list all branches in the repository:
git branch


This lists the new branch and the master branch.

Switch branches

Command line to switch to a branch:
git checkout about-section


Run this command to confirm branch switch:

git status


Branch changes

Once switched into the branch, any changes to the files 
locally will be for this branch only.

Issue commands such as "commit" like you would normally.

Finally, push the commits out to the respective branch.

The command would look like:
git push origin about-section

This pushes the changes out remotely to the 
"about-section" branch.

Merging the branch into master

First we need to switch back into the master branch:
git checkout master

Confirm that we are in the right branch:

git branch

Now issue the merge command:

git merge about-section

This pulls down the branch into the master branch.

Then push the changes out to the remote repository:

git push origin master


And hopefully...

No conflicts?


If there are conflicts...

Using a visual diff tool will be to your advantage.

Download one of these:


Or use the built-in merging tool with the

previously discussed GUI clients.

Git Workflow

The master branch is our deployment branch.
Any deployments to production will come directly from 
the master branch.

Any MAJOR features to the site will need to create a 
"feature branch" and then merged back into the 
master branch.

This workflow will now be our de facto standard 
here at MMGY. 

Extra Credit

Cheat Sheet:

eBooks:
Websites:




Questions?

git training

By spfaffly

git training

  • 4,772