Common git commands This section provides a list of commonly used git command invocations. All commands shown, except the first one (git clone must be issued from within the project directory. To clone a git tree for first time or temporary use via http, use:$ git clone <URL> The <URL> value for OpenPOWER Foundation GitHub projects can be found on the project web pages. They generally take the form of https://github.com/OpenPOWERFoundation/project_name where the project_name can be found on the OpenPOWER Foundation Git Hub community page at https://github.com/OpenPOWERFoundation. The result of this command will be a new directory with the same name as the project and in which will be the project files. Trees can only be cloned once. To update a tree, use a git pull or git merge command. When cloning from a private tree, you will be prompted for your GitHub userid and password. To update a git tree with new files from the remote repository, use:$ git pull This command assumes that the local tree has not been updated since the clone or last pull. If updates have been made to the local tree, the command will fail. Use the git status command to see what has changed in a local tree. When pulling from a private tree, you will be prompted for your GitHub userid and password. To see the status of the local repository, use:$ git status This command identifies files which have changed in the local repository and provides suggestions on how to handle. Adding the -s parameter to the end of the command will provide a simplified view in which changed files are listed with flags such as M for modified files, A for newly added files, and ?? for new or unknown files. This parameter also suppresses suggested action information for the files. To add a new file or directory to a git tree, use:$ git add <new_file> The <new_file> value can be either a file or a whole directory and may include the path to the target file or directory. This command will convert the status of file in the git status -s command from ?? to A or move it from the "Untracked files" section to the "Changes to be committed" section of the git status command. To remove a file from a git tree, use:$ git rm <file> The <file> value must be a file and may include wildcard characters or the path to the target file. This command will both remove the file(s) from the directory and the git tree. Removed files will show in a status modifier of D in the git status -s command and be reflected in the "Changes not staged for commit" section of thegit status command with a "deleted:" status. To remove a directory from a git tree, use:$ git rm -rf <directory> The <directory> value must be a directory name and may include wildcard characters or the path to the target directory. This command will remove all files in the directory from the git tree, but will not remove the directory locally. Standard operating system commands such as the Linux rmdir <directory> command must be issued separately to remove the local directory. All removed files will show in a status modifier of D in the git status -s command and be reflected in the "Changes not staged for commit" section of thegit status command with a "deleted:" status. Because git does not track directories, they will not be reflected in status. To move or rename a file or directory in a git tree, use:$ git mv <source> <destination> The <source> value must be a file or directory and may include the path to the target file. The <destination> value may be a file (if renaming a file) or a directory if moving a file or directory. This command will move or rename the file(s) in both the local and remote the git trees. To commit all local changes to the staging area for a git tree, use:$ git commit -a This command will invoke an editor for a commit message. A well-formatted commit message includes a title on the first line, a blank line, one or more lines of details describing the changes, and a Developer's Certificate of Orig (DCO) Sign-off statement at the end. Signed-off-by: Your name <your_email@domain.com> For information on the DCO, see Developer Certificate Of Origin at http://elinux.org/Developer_Certificate_Of_Origin. To push all locally staged changes to the remote git tree, use:$ git push When pushing to a private tree, you will be prompted for your GitHub userid and password. To see what tags exist in a git tree, use:$ git tag To create a new tag locally, use:$ git tag -a <tag_name> -m"text" The tag_name represents the simple value of the tag. The text string provides more description of the tag for readibility. This command simply tags locally. See the next command for how to push the tag to the remote repository. To push a new tag from the local tree to the remote tree, use:$ git push origin <tag_name> This commands assumes the git tag command has been run on the local tree. To discard changes from a locally changed file and return to the last copy, use:$ git checkout -- <file> The <file> value must be a file and may include wildcard characters or the path to the target file. To identify what changes have been made locally to a file use:$ git diff <file> The <file> value must be a file and may include wildcard characters or the path to the target file. The output will be in format similar to the standalone diff command. Additional resources about git can be found online at the following locations: The GitHub Glossary at https://help.github.com/articles/github-glossary/. This site provides a list of common terms associated with git and GitHub. The GitHub Git Cheat Sheet at https://training.github.com/kit/downloads/github-git-cheat-sheet.pdf. This two page pdf provides a quick summary of many common commands. The Git Reference at http://gitref.org/. This is a deeper and more comprehensive reference of important commands. The git-scm.com Documentation library at http://git-scm.com/doc. This site provides education in the form of books, videos, and other tutorials for common git activities.