####### getting a repository git clone ssh://user@circe.rc.usf.edu/shares/rc/git/puppet.git git clone -b branch_name ssh://user@circe.rc.usf.edu/shares/rc/git/puppet.git branch_name/ (clones branch_name into folder called branch_name) * update repo.git/hooks/post-receive to automatically apply changes (ala rc puppet) via git's post-receive event ####### show quick author commits with rev numbers git blame filename git blame modules/access/manifests/init.pp ##### start git editing git init (begin using git) ####### creating a branch (safely edit) ####### must be within local git folder, e.g. ~/puppet/development git branch -a (view branches) git branch name_of_branch git checkout name_of_branch (switch to branch) || git checkout -b (name) * may need to run git push -u origin name_of_branch * ###### deleting a branch git branch -d (name of branch) git branch -D (name) delete unmerged branch ##### merging a branch into production (via workstation!) git checkout production git merge testing git push ####### show commit details git log --color --graph --stat git log --follow filename = show commits on file name git log -p filename = show commits and git diff on file name git log -L startline,offset:filename = show commits on specific line in file name gitk --all (gui) ####### show git changes git whatchanged -n <- shows last n changes along with rev numbers git whatchanged -n(commits) modules/access/manifests/init.p git whatchanged -2 -p modules/access/manifests/init.pp git whatchanged (all changes, author listed, file listed) git whatchanged -2 -n REVNUM git log --color --graph git log --color --graph --follow 'filename' <- show all commits on filename git log --since=YYYY-MM-DD | --until=YYYY-MM-DD ####### git tagging * lightweight tag = points to a specific commit; * annotated tag = stored as full object in db git tag -a v0.0 -m "m" = create annotated tag v with message "m" git tag -a v1.2 $commit = create annotated tag on specific commit git tag v0.0 = create lightweight tag git push origin $tag = push single tag to repository git push origin --tags = push all tags to repository git tag -d $tag = delete tag git push origin --delete $tag = delete tag from repository ####### show git rev details git show REVNUM(commit hash string, i.e. 5b6374b9c55383d9f4fd2e937b3e114e617c9254) git show -Unnnn = show nnnn lines (for seeing entire file, etc..) git tag --contains COMMIT ; display tags/branches that contain commit ###### commit stuff git tag -l --contains=COMMIT (displays tags with commit in it) git config --global user.name "username" git config --global user.email "email" git config --list (view setup config) git commit -a (all files) -v (show differences) -m "message" git push localb remoteb (push changes to REMOTE SOURCE) git fetch git rm --cached file = remove commit (removes file from repository!) git checkout -- file = undo changes to file git checkout --ours|theirs path/file = resolve easy conflict due to pushing in primary branch commit and push #### boo boo's (fix shit commits and pushes) --hard = resets index and working tree; changes to tracked files are discarded --soft = doesn't reset index and working tree; but does reset head to commit; files are changed * pushed git reset --hard [HEAD~n|commit-id] (undoes a local commit that hasn't been pushed and restores original file contents) git push -f (intentionally deletes history because step above leaves your branch a commit behind) git revert SHA && git push (will take inverse of last commit and reset master, publicly) * not pushed git reset --soft [HEAD~n|commit] (undoes a commit and push; leaves file altered) ##### pull a file from an earlier commit * clone repository first into another directory git checkout commit git checkout 'branch'(if applicable)~nrevisionsago FileName = pulls a file from an earlier revision ##### reset file 1.) delete file 2.) git ls-files -d (lists deleted files) 3.) git checkout branch(in question) filename #### steps to commit 1.) sudo git add file 2.) sudo git commit -a -v -m "message" 3.) sudo git push; use git push --all if you have a separate branch or specify ref, e.g. git push rsge_desantis 4.) login to puppet/ezproxy server and pull the changes from the repo (ssh root@puppet; cd /etc/puppet; git pull or sudo git pull jfargen@circe.rc.usf.edu:/shares/rc/git/ezproxy.git master) ### correct a commit or commit message git commit --amend (may need to git add file(s)) git commit --amend -m "New message" ### correct a horrible mistake made by author git reflog (find the last known good state made by author) git reset HEAD@{index} (index = number) ### correct commit to wrong branch NOT PUSHED git reset HEAD~ --soft git stash cd real_branch git stash pop git commit -a -v ##### create a clipboard of changes without committing git stash save "message to clipboard" ### stashing changes * useful in the event you have to stop working and fix another piece of code * conflicts are resolved as in MERGE issues git stash - stash current changes with default message (relates to HEAD and branch) git stash name "blah" - stash current changes with "blah" message git stash show - shows current stash git stash list - shows a list of stashed changes which can be applied git diff stash@{0} - shows git diff of changes between stash@{0} and current HEAD git stash pop - restores the working state before the stashing git stash apply n - restore stash "n" to current state git stash clear - clears ALL stashes ##### git pull errors git pull --rebase git merge master - merge changes into branch (master in this case) git merge origin/master - more precise way of merging git fsck - check possible corruptions on objects git gc - clean up dangling commit errors git ls-remote - checks refs which exist; permissions may be an issue #### get update without pulling git fetch git remote update git status ########### create default (master) git repository * project should be started on local machine first (for intial file uploading) * steps should be followed in exact order * may need to run "git config --add receive.denyCurrentBranch ignore" on repo host 1.) repo (remote machine) mkdir /home/f/foo/repo.git (.git is unnecessary) cd /home/f/foo/repo.git git init (check on git config options for repo tweaking) find objects -type d -exec chmod 02770 {} \; 2.) local repo (workstation) change directory into foo git init (ensure correct details with git config --list) git add * (add all files in directory) git commit -m "Message" git remote add origin ssh://user@host:/home/f/foo/repo.git (created in step 1) git push -u origin master (a branch will be created after this; can rename using -m old new) * When using an already existing directory with content, use step 1 but add files and then git commit -m; clone can then occur * Repo should be outside of directoy with content to ensure proper overwrites ######### create non default (production) git repository 1.) repo (remote machine) mkdir /home/f/foo/repo.git (.git is unnecessary) cd /home/f/foo/repo.git git init (check on git config options for repo tweaking) git checkout -b production find objects -type d -exec chmod 02770 {} \; 2.) local repo (workstation) change directory into foo git init (ensure correct details with git config --list) git add * (add all files in directory) git commit -m "Message" git remote add origin ssh://user@host:/home/f/foo/repo.git (created in step 1) git branch -m production git push -u origin production (a branch will be created after this; can rename using -m old new) ** If creating additional non "master" branches, checkout new branch ** and push "initial" commit using `git push -u origin NEWBRANCH`