Git Survivors Guide

  git clone
    Download (clone) a copy of a remote git repository
  git log
    Show the commit log
  git log -n1 --pretty=format:%h-%ct
    Show an abbreviated hash code and a unix timestamp of last commit
  git status
    This will output some information about the state of the local copy of the
    cloned repository. It reports the branch name, the number of commits that
    have not been pushed, a list of files staged for commit, and a list of
    untracked files.
  git branch
    List all local branches
  git branch -a
    List all branches (local and remote)
  git branch local-branch-name remote-branch-name
    Make new local branch
  git checkout -b local-branch-name remote-branch-name
    Make new local branch and checkout the branch
  git checkout local-branch-name
  git stash save
    Use this if you have locally changed files (not yet committed) before you
    use "git pull"
  git pull
    Use this if you have no local commits that have not been pushed
  git pull --rebase
    Use this if you have local commits that have not been pushed
  git stash pop
    If you stashed local changes before the pull this reapplies your changes
  git add [file1 [file2] ...]
    Mark a file to be committed on next use of commit. The "git status" command
    will show the added files as staged, and the staged files will not be shown
    in the output from "git diff".
  git add --interactive [filespec]
    Interactively add (stage) files for the next commit
  git reset <file>
    Unstage a file so it won't be committed
  git rm
    Removes a file (or files) from the list of staged files. For unstaged files
    the file(s) will be removed from the filesystem and deleted from the remote
    repository.
  git commit
    It usually only commits staged changes if no file names are specified on
    the command line. Use git add or git rm to stage changes ready for commit.
  git commit --amend
    Make changes to a commit that has not been pushed
  git push [-a]
    Push recent local commits to the remote git repository
  git format-patch [-n]
    where n is the number of recent commits to make patch files for
  git am
    apply patch(es) created by 'format-patch'
  git am --abort
    Abort the patching operation and restore the original branch.
  git clean [-df]
    Get rid of files
  git clean -xdf
    Don't use ignore files when cleaning the source tree.
    Useful when it says a merge is required to avoid clobbering some files
    so it won't change branches.
  git reset [--hard]
  git config [--global]
    Automatic text file line ending conversion can be set in ~/.gitconfig
    using "autocrlf = input" under the [core] section.
    The user name and email to be recorded in commits can be set in the
    [user] section.

Additional information:
The file .git/config has the URL for the source of the remote repository

After amending a comment for an unpushed commit that was not the HEAD commit, use the following to fix up the log entry:
git rebase -i HEAD~n
where n refers to the nth commit before the current HEAD commit

TODO:

  • Add info on marking files as binary
  • Add info on ignoring certain files so they won't get checked in
  • Add how to clean up after a conflict when applying an am patch

git am -3

  • Update “git config” info to state command options to set autocrlf, user, and email.
  • git commit -a

Will record changes in directory tree (ie. files removed via rm instead of git rm).

  • Add information about 'gitk' and 'git gui'
  • Add information about setting some config options

user.name=Real Name
user.email=email@my.domain
push.default=current
core.autocrlf=input (use auto on Windows)

A nifty view of branches, tags, and other refs:
git log –oneline –graph –decorate –all

docs/git_survivors_guide.txt · Last modified: 2015/10/17 18:25 by admin
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Valid XHTML 1.1 Valid CSS! Best viewed with any browser Ohloh profile for Kevin Cozens Driven by DokuWiki Recent changes RSS feed