title |
---|
Git Cheatsheet |
Version Control for the Humanities with Git Workshop
pull or init > (add / rm / modify) > commit > push
git init
to start watching the current directorygit add foo.txt
to stage the filegit commit -m "my first commit notes"
describe your changesgit remote add origin https://github.com/denten/dhnotes
point to the remote repogit push -u origin master
push to remote for the first time
git clone https://github.com/denten/dhnotes
clone the remote then rejoin the
above instructions at step 2.
git pull
before doing anything
note:
git pull
does agit fetch
followed by agit merge
git add/rm foo.txt
Stage any new files you want to commit. Modified files will be staged
automatically. git reset
to unstage. Add new files with add and remove with
rm. Use the --amend flag to amend the commit before pushing
use
git commit -am "notes go here"
to combine add and commit in one line
git push
to push changes to the server
-
Click to fork, by going to the team's project repository (R1). This creates a copy or a "fork" of the repository in your own account (R2).
-
Clone your own repository (R2) down to your machine (L2).
-
Make some changes.
-
Push your changes from your local machine (L2) to your own remote repository (R2).
-
Navigate to your repository (R2) using your browser. Click to create a "pull request," which asks the moderators of the teams repository (R1) to accept your changes from R2.
You will have to go through this process for each change. If you contribute frequently to the same team project you may want set up a sync between R1 and R2. In the language of Git you will set R1 as "upstream" of R2.
git diff
to see the diffs on your modified files
git status
is your best friend
git log --graph
git remote -v
to show fetch and push locations
git remote show origin
- Make a new branch and switch to it:
git checkout -b edits
- Edit your files
- Commit your changes to advance head:
git commit -am "notes"
- Switch back to master:
git checkout master
- Merge the patch:
git merge edits
Submodules are repositories within repositories. Try to avoid this, but useful for syncing your vim settings, for example, which will have other git repos attached. Also useful to manage GitHub Wikis.
git clone --recursive git://github.com/foo/bar.git
to clone including the
submodules
git submodule add https://github.com/user/repo
to add submodules to an
existing project
git submodule init
if the files are not pulling
git submodule update
to update your submodules
git submodule foreach git pull origin master
or git pull --recurse-submodules origin master
to upgrade all submodules
if the head gets detached run git checkout master
git submodule deinit
followed by git rm name-of-submodule
to remove
submodule (Git 1.8.5+)
if the submodule head gets detached, run $ git checkout master
from the
submodule directory followed by git pull
. See this
tutorial
for more information. See the Github Tips section for Wiki handling.
-
Use SSH instead of HTTPS to avoid storing unencrypted credentials locally (or logging in with every push / pull). Follow the instructions here to set up ssh. SSH will allow you to use your keyring on a Mac or do
ssh-add
on Debian linux once per session. -
To clone a project without the top directory run
$ git clone PATH .
But that will only work for an empty directory. If the directory is not empty follow thegit init
route (as you would with a new repo andremote add origin
as usual. -
git add -A
to add all untracked files and directories
git checkout -b new_branch old_branch
git push origin new_branch
- GitHub Pages TBA
- Add your wiki to the repo as a submodule by running
$ git submodule add -b master [URL to Git repo].wiki.git
. The submodule allows you to edit the wiki locally, in markdown. Use gollum to preview locally, if needed. - Note that the submodule points to a specific revision. Make changes and
commit / push in the submodule as usual. Run
$ git submodule update --remote
in the parent directory to update the pointer to the correct revision. - This will mean that for every change in the wiki you have to push twice, once to the wiki (from the submodule directory) and once to the main repository, from the root repo folder.
- The wiki tool on gitHub will always have the latest revision.
- If the head gets detached run
$ git checkout master
in the submodule directory.
- Install p4merge on Mac, WinMerge on Windows, or Meld on Linux.
- run
git config --global merge.tool p4merge
to set your default merge tool git mergetool
after "unable to merge" errors