FANDOM


Set upEdit

  • Install git
  • Introduce yourself
git config --global user.name "Your Name Comes Here"
git config --global user.email you@yourdomain.example.com
Notes: --global makes it global for you. --system makes it for everyone. neither makes it for the specific repository
  • Set editor to one of these:
git config --global --add core.editor "open -W -e -n"
git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
git config --global core.editor "vi"
git config --global core.editor emacs
Notes: Set up the editor for git to use for entering comments, so you don't have to use the -m option
  • merge tool:
git config --global merge.tool kdiff3


  • color output:
git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto

GUIEdit

gitk

Initialize Repository for an existing projectEdit

CD to project directory

git init

Creates .git folder.

Add files and commit

git add .
git commit

The 'add' command stages the file.

Clone a repositoryEdit

To get files from an existing repository. Example:

git clone git://github.com/schacon/grit.git

or

git clone git://github.com/schacon/grit.git mygrit
git clone http://github.com/schacon/simplegit-progit.git

LifecycleEdit

Untracked
'add' --> Unmodified
'edit' --> Modified
'stage' --> Staged
'commit' --> Unmodified
'remove' --> Untracked

Modifying filesEdit

  • Edit a file, and it's now considered "Modified"
  • Then you stage the file by using the 'add' command on the file.
    'add' is not just for adding the files for the first time. It's also for move a changed file from work to staged.
  • Then 'commit' your changes, which moves the files from staged to committed.

You can skip the stage step by doing a commit with the -a parameter. i.e.

commit -a

Check statusEdit

git status

Ignore filesEdit

Create .gitignore text file, and add files one line at a time; supports wild cards

git add .gitignore
git commit

DiffingEdit

To see what's changed by not yet staged:

git diff

compares working directory with staging area.

To see what's changed between staged and last commit:

git diff --cached


Removing a fileEdit

Remove from tracked, staged, area and commit:

git rm
commit

However, only deleting it from disk without git, it will show up in "changed by not updated / unstaged" area, which will require a git rm.

If the file as modified, -f is used to force removal.

If you accidentally added a file to git, and wish to remove it only from git, but not the disk, use:

git rm --cached (filename)

Using wild-cards with rm requires backslash. eg.:

git rm log/\*.log
git rm \*~

Moving / Renaming filesEdit

git mv file_from file_to

This the same as:

mv file_from file_to
git rm file_from
git add file_to

Even in the latter case, git figures out it's a rename.

View Commit HistoryEdit

list commits made in the repository

git log

mode condensed:

git log --pretty=oneline

with abbreviated status:

git log --stat

use -p to show diff introduced in each commit, and -2 to limit output to last 2 entries:

git log -p -2

custom format:

git log --pretty=format:"%h - %an, %ar : %s"


BranchingEdit

Create a new branch:

git branch experimental

List branches (the asterisk marks the branch you are currently on)

git branch

Switch to the experimental branch:

git checkout experimental

make changes, and edit. Then switch back to master and merge:

git checkout master
git merge experimental


If there's conflicts, makers will be left in the files. type git diff to see

To delete the experimental branch:

git branch -d experimental

will only delete it if the changes are in the current branch.

To delete a branch just to throw it away without merging it, use:

git branch -D crazy-idea-branch



UndoEdit

Before commit:

git reset --hard

Or one file at a time:

git checkout myfile.txt

which restores a file from the last revision (like svn revert path)

To fix the last commit message:Edit

Example:

git commit
git add forgotten_file
git commit --amend

Another way:

  • Forgot something in the last commit:
git reset --soft HEAD^
git add forgot.txt these.txt files.txt
git commit

To undo a commit:

git reset HEAD^

or to ammend it:

git commit --amend

TaggingEdit

Will tag the current files with "name"

git tag -a name

Show current tags:

git tag -l

Show changes associated with a tag:

git show tag



Update RepositoryEdit

To get the latest from the repository (similar to Subversion's svn update):

git pull

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.