Skip to content

Instantly share code, notes, and snippets.

@blakerohde
Last active January 29, 2017 07:11
Show Gist options
  • Save blakerohde/6138015 to your computer and use it in GitHub Desktop.
Save blakerohde/6138015 to your computer and use it in GitHub Desktop.
Git Quick-Start Notes

Git Quick-Start Notes by Blake Rohde, 2013

Create the repository on the server

$ mkdir PROJECT.git
$ cd PROJECT.git
$ git init --bare

Clone the repository on a client

$ git clone ssh://SERVER_ADDR:SSH_PORT/PATH/TO/PROJECT.GIT
$ cd PROJECT/
$ git config user.name "YOUR NAME"
$ git config user.email "YOUREMAIL@EXAMPLE.COM"

Editing, archiving, and sharing files

  1. If others are working on the same repository, always pull the latest copy of the files before working on them:
$ git pull
  1. Create or edit your files as needed.
  2. When you want to archive a file, you need to COMMIT it locally on your computer. First, you should check the status of your files.
$ git status
  1. The git status will give you a list of files that have been added, modified, or deleted since the last COMMIT or PULL. Notice the sections these file lists are grouped by; look for "changes staged for commit", "changes NOT staged for commit", and "untracked files". Typically you want to COMMIT all modified and added files, so you must ADD the files to be COMMITted:
$ git add .
  1. If you want to COMMIT your deleted files too, then you must ADD the updated status of these files:
$ git add . -u
  1. Now all of your files should be in the "changes staged for commit" section of the git status command, so COMMIT/archive your changes locally:
$ git commit -m 'MESSAGE ABOUT CHANGES MADE'
  1. When you are ready to upload your COMMITs/changes to the server for your collegues to PULL down to their computer, you need to PUSH the COMMITs:
$ git push origin master

View and revert changes made to files

If you want to view the changes between your current copy of a file and the most recent COMMIT or PULL of the file, you can use DIFF. This will show you the changes you have made, line-by-line:

$ git diff FILENAME

If you want to revert the changes made since your last COMMIT or PULL, you can use CHECKOUT:

$ git checkout FILENAME

If you want to revert all changes made to all files in a repository since your last COMMIT or PULL, you can CHECKOUT all files:

$ git checkout .

Submodules: Git repositories inside Git repositories!

Here is the low-down:

$ cd PROJECT
$ git submodule add ssh://SERVER_ADDR:SSH_PORT/PATH/TO/PROJECT.GIT /PATH/TO/LOCAL/LOCATION/FOR/SUBMODULE
$ git commit -m 'ADDED SUBMODULE TO PROJECT'

If you want to COMMIT, PUSH, PULL, etc inside the submodule, you just 'cd' into the submodule directory and perform the normal Git operations. For more info see: http://git-scm.com/book/en/Git-Tools-Submodules .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment