Sunday, November 16, 2014

Some Git Quick Command Line Action Reference

Create new repository:
git init

Add remote repository url:
git remote add origin [url-to-repository]

Set remote repository url:
git remote set-url origin [url-to-repository]

Get current remote repository url:
git config --get remote.origin.url

Be sure to know which one to use!!
git reset [--soft|--mixed|--hard|--merge|--keep]

Add Sub-Module/Sub-Repo:
git submodule add [url-to-repository]

Update Sub-Module/Sub-Repo:
git submodule update

Remove reference to a Sub-Module:
git rm -rf --cached [folder-name]

Creates a new local branch:
git checkout -b [branch-name]

Switch to branch:
git checkout [branch-name]

Delete local branch:
git branch -d [branch-name]

Delete local branch(FORCED):
git branch -D [branch-name]

Pushes the current branch, -u sets also the pull branch:
git push -u origin [branch-name]

See the list of your branches:
git branch

Add all new files:
git add -A

Commit changes:
git commit -m"[Your message here]"

Commit changes as someone else(blame - not really):
git commit -m"[Your message here]" --author="John Doe <john@doe.com>"

Push Commits:
git push

If when checking you git status you see "Head detached from xxxxx" using the following is the simplest solution:
git config --global push.default simple

Fetch remote commits:
git fetch

Update local copy:
git pull

Create Tag:
git tag your-tag-label

Push tag: (Use -f to override existing tags in the remote repo)
git push origin ["your tag label"] -f

I know there are far more commands, but as a starting point this is a good collection of actions.
If you have some common commands you use that I've left out, let me know.

No comments:

Post a Comment