Git is a powerful version control tool. The git command list below contains the more commonly used commands for creating & controlling a git repository. For a guide on connecting a local git repository to BitBucket, check out my guide Initialise a Local Git Repository & Connect to Remote BitBucket Repository.
- Add current directory as a repository
[stuart@asuka MyProject]$ git init
- Add all files to repository
[stuart@asuka MyProject]$ git add *
- Add specific file to repository
[stuart@asuka MyProject]$ git add **file**
- Commit changes to all files (
-m "message"
is optional)
[stuart@asuka MyProject]$ git commit -a -m "**message**"
- Commit changes to specific files
[stuart@asuka MyProject]$ git commit **file** -m "**message**"
- Push commit changes to repository
[stuart@asuka MyProject]$ git push
- Pull changes from git repository
[stuart@asuka MyProject]$ git pull
- Create a new branch
[stuart@asuka MyProject]$ git checkout -b **new_branch**
- Push new branch to remote server
[stuart@asuka MyProject]$ git push origin **new_branch**
- View current branch and other branches (local only)
[stuart@asuka MyProject]$ git branch
- View current branch and all available branches (includes remote origin)
[stuart@asuke MyProject]$ git branch -v -a
- Change current branch (to remote branch)
[stuart@asuka MyProject]$ git checkout -b **remote_branch** origin/**remote_branch**
- Show uncommitted changes (add
--name-only
to get a list of files with changes)
[stuart@asuka MyProject]$ git diff
For more information about the git command & available command options, check out the manual page for git (man git
) or see the official git documentation.