Skip to content
erumeldir edited this page Nov 19, 2013 · 1 revision

I'm not super familiar with gui git tools so I'll just put up the commands for basic command line operations here for now.

Setup

1. Configure user name / password

Set your name and email so that github knows to allow push/pull and so we can see who did what.

git config --global user.name "Your name here"
git config --global user.email [email protected]

2. Clone the repo

To clone the repository run

git clone <repo url> <new local repo name>

This will create a copy of the repository in your current directory with the given name.

Making Changes

To make local changes, you need to stage the files that you want changed, then do a local commit

Adding changes and Checking staged files

Adding is done with the following command:

git add file1 file2 file3

To check the status of which files have been staged for commit and which have been modified but are not ready for commit, run:

git status

To remove files from the working git tree (will still be on local storage but no longer tracked by git, run

git rm file

Note: Do not add binary files or assets to the repo.(.exe, .jpg, .mov, .dll, etc...) The repo will grow very large VERY quickly. Git doesn't really know how to handle these files well. If a file of an undesired type is showing up in the changed files list when git status is run, check your .gitignore and add the file type to the list. ###Committing Local Changes To make a local commit, run

git commit

This will prompt you with a popup / vim asking for a commit message. To bypass this step, you can run:

git commit -m "commit message"

If you know that all the changes you make are desired commits, you can run

git commit -a[m] ["commit message"]

to bypass having to manually add every file with git add ##View Project History The default logging/info tool git log has so many options, but to create a good overview of the tree so far I use:

git log --decorate --oneline --graph --color --all

This will create a compact colored graph that displays a shortened commit hash with the description of the commit (limited at 50 chars i believe). If you want to see the changes of a specific file, you can use

git log -p [filename]

and I think this works as well

git show <commit number>

If you wanna be really fancy. Here's an alias that makes some REALLY pretty graphed log output.

git config --global alias.lg log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n''          %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all

##Branching ###Create Branch Branches are awesome! To create a branch use:

git branch branchname

To see a list of all existing branches, run

git branch

###Checkout Branch To switch to a branch use

git checkout <branchname>

Note: You can only check out a branch if you have no uncommitted files. It is possible to stash these files temporarily...but it may not be the best thing. ###Merging Once files have diverged, the branches need to be merged back together for all the changes in both branches to be kept. To merge, first checkout the branch you are merging into, then run branch merge

git checkout master
git merge --no-ff branchname

Also, lets try to always use the --no-ff option. This prevents git from merging every change made in the feature branch into the master (shown on a graph it would look like a straight line instead of a branch). ###Deleting Branches If a branch has run its lifespan (ie feature is complete) you can delete it with

git branch -d branchname

This will only work after a merge is done. A branch can also be forced to be deleted at any time (say a feature does not go as intended) with

git branch -D branchname

##Push and Pull ###Pulling New Changes git pull will do fetch the head of the branch you are currently on as well as merge all changes into the repo's branch. To pull from a branch you don't currently have a local copy of you can run

git pull origin branchname

Alternatively, this should work

git checkout branchname

it should prompt you to create a local copy of the branch.

To check for changes in the remote branch without attempting to merge, run

get fetch origin branchname
git log -p HEAD..FETCH_HEAD

HEAD..FETCH_HEAD is the placeholder for the last fetched branch. ###Push to origin To push a branch to the origin

git push origin branchname

You can also just run git push and git will configure a default push to always push to the origin repo (once you set it the first time).

##Branching Scheme Here's the link to the pretty good branching scheme! :) http://nvie.com/posts/a-successful-git-branching-model/