git memo

Mar 25, 2010   coding
create new repo with first commit and push

assuming you have code in a directory called hayate

  • cd into hayate directory cd /path/to/hayate
  • git init
  • git remote add origin git@hostname.com:hayate.git
  • then git add .
  • git commit -a -m 'added hayate repo'
  • then for the first push: git push origin master:refs/heads/master which creates the master branch
tagging
git tag v1.0 -m 'my first tag'
git push --tags
git tag -l
clone into current directory
  • git clone git@hostname.com:hayate.git . <- note the dot (hayate directory will not be created)
change working branch
  • git branch -l lists local branches
  • git checkout <branch-name> switches working branch to "branch-name"
remove an added file or directory (before it is committed)
  • git reset <file-or-directory-name>
add submodule (an external repository) within local source tree
  • git submodule add <repo-url> <local-path>
    i.e. git submodule add git@hostname.com:hayate.git hayate
checkout a submodule
  • git submodule update --init
create a new remote branch tracking it locally
  • git checkout -b <branch_name>
  • git push -u origin <branch_name>
  • git checkout <branch_name> to switch to the new branch
start tracking a remote branch
  • git checkout --track -b <local name> origin/<remote name>
delete a remote branch
  • git push origin --delete <branch_name>
delete local branch
  • git branch -D <branch_name>
revert a merge
  • git revert -m 1 merge_hash
to suppress the following warning
warning: You did not specify any refspecs to push, and the current remote
warning: has not configured any push refspecs. The default action in this
warning: case is to push all matching refspecs, that is, all branches
warning: that exist both locally and remotely will be updated.  This may
warning: not necessarily be what you want to happen.
warning:
warning: You can specify what action you want to take in this case, and
warning: avoid seeing this message again, by configuring 'push.default' to:
warning:   'nothing'  : Do not push anything
warning:   'matching' : Push all matching branches (default)
warning:   'tracking' : Push the current branch to whatever it is tracking
warning:   'current'  : Push the current branch
  • git config [--global] push.default current (--global is optional)