Commands
- git status
- Displays the status of the repository, indicating whether a file has been changed or deleted, for example. Or, whether a new file has been added that Git is not aware of.
- git clone git@REMOTE_HOST:USER/REPO.git
- Clones
REPObelonging toUSERfromREMOTE_HOST. For example, git clone git@github.com:code-warrior/dockspacer.git clones thedockspacerrepository belonging to usercode-warriorfrom thegithub.comremote host, which happens to be a web site, to your local computer. - git checkout -b hotfix
- Creates a new branch named
hotfixand switches to it. - git diff
- Displays the changes made to one or more files that has not been added to the staging area, also known as the index.
- git diff --cached
- Displays the changes made to one or more files that has been added to the staging area/index, but has/have not been committed.
- git add .
- Adds the current directory (
.) to the staging area/index. - git commit -m 'YOUR MESSAGE HERE'
- Commits the changes in the staging area/index to the repository with the message (
-m)YOUR MESSAGE HERE. The message must be wrapped in inch marks ("") or foot marks (''), and the convention is to keep the message under 60 characters. - git pull
- Fetches the changes from the remote repository, then merges them into the local repository.
- git push
- Pushes and merges your local changes to a remote repository.
Command Prompt
Authored by Shawn Pearce, the Git-based prompt I use provides some useful information about the current state of the Git repository without having to issue a command. An explanation of some of its icon characters follows. You can read more about the project on GitHub.
(master)- You’re on the
masterbranch, which is local and does not exchange files with a remote branch. (dev <>)or(dev=)- You’re on the
devbranch, which exchanges files with a remote branch. (master %<>)or(master %=)- You’re on the
masterbranch that exchanges files with a remote branch (<>or=) and contains a file or a folder with new files that is not being tracked (%). (dev *<>)or(dev *=)- You’re on the
devbranch that exchanges files with a remote branch (<>or=) and contains one or more files that have been modified (*) in the working directory but have not been committed to the staging area, or index. (master +<>)or(master +=)- You’re on the
masterbranch that exchanges files with a remote branch (<>or=) and contains one or more files that have been placed in the staging area/index (+) and are ready to be committed. This is the result of having issued the git add . command or the like. (dev>)- You’re on the
devbranch that contains changes not pushed to the remote branch (>). (master $)- You’re on the
masterbranch that contains stashed changes. This is the result of having carried out the git stash command.
Messages
The following means you’re issuing Git commands within a folder/directory that is not under Git control.
fatal: Not a git repository (or any of the parent directories): .git