Git
Reference
See also Vim#Git
Guides
- Git wiki
- Pro Git [2]
- Arch Linux Wiki: Git
- Git cookbook
- git - the simple guide
- http://www-cs-students.stanford.edu/~blynn/gitmagic/
- http://gitimmersion.com/
- http://blog.quickpeople.co.uk/2013/07/10/useful-github-patterns/
- http://marklodato.github.com/visual-git-guide/index-en.html
- http://try.github.com/ - interactive introduction
- http://pcottle.github.io/learnGitBranching/ - like vim golf. ish.
- https://speakerdeck.com/simonclouds/understand-git - nice one page intro slide
- http://marklodato.github.io/visual-git-guide/index-en.html
- http://www.wei-wang.com/ExplainGitWithD3/ [3]
Articles
- Understanding Git Conceptually
- pushing and pulling
- Understanding the Git Workflow
- http://durdn.com/blog/2012/12/05/git-12-curated-git-tips-and-workflows/
- https://blogs.atlassian.com/2014/01/simple-git-workflow-simple/ [5]
Consider how a common Git workflow falls apart.
Create a branch off Master, do work, and merge it back into Master when you’re done
Most of the time this behaves as you expect because Master changed since you branched. Then one day you merge a feature branch into Master, but Master hasn’t diverged. Instead of creating a merge commit, Git points Master to the latest commit on the feature branch, or “fast forwards.” (Diagram)
Unfortunately, your feature branch contained checkpoint commits, frequent commits that back up your work but captures the code in an unstable state. Now these commits are indistinguishable from Master’s stable commits. You could easily roll back into a disaster.
- A successful Git branching model [6]
- https://gist.github.com/jbenet/ee6c9ac48068889b0912
- A Rebase Workflow for Git
- http://mercurial.selenic.com/wiki/GitConcepts
- http://www.mail-archive.com/dri-devel@lists.sourceforge.net/msg39091.html
- http://joeyh.name/blog/entry/git_push_over_XMPP/ - an idea..
- http://marklodato.github.com/visual-git-guide/index-en.html
- https://ventrellathing.wordpress.com/2013/01/25/git-a-nightmare-of-mixed-metaphors/
- http://blog.moertel.com/posts/2013-02-18-git-second-order-diff.html
Config
git config --global --edit open config file in editor
git config --global user.name "Your Name Here" git config --global user.email "your_email@youremail.com"
git config color.ui true turns on colour for everything git config format.pretty oneline
git config --global push.default matching (will be default soon)
git config --global help.autocorrect 10
git config --global credential.helper 'cache --timeout=3600'
The credential helper only works when you clone an HTTPS repo URL. If you use the SSH repo URL instead, SSH keys are used for authentication.
Aliases
Bare repo
To convert repo to bare repo; [9]
mv repo/.git repo.git git --git-dir=repo.git config core.bare true rm -rf repo
Commands
See Vim#Git
Repo config
- git config receive.denyCurrentBranch warn - allow pushing to a non-base repo
git repo-config core.sharedRepository true - allow access by multiple users
Adding files
git add . # add file to Index (staging)
git add * # add all (except those in .gitignore) files to Index
git add -p # add hunks seperatly [10] # y = stage, n = don't stage, q = quit,
Commits
Committing moves files from Index into HEAD.
git commit -m Commit message goes here.
git commit -a git adds at the same time
git commit --amend without file change, alter last commit msg
Remotes
git remote add origin <server> git remote show origin git remote set-url origin git@gitrepo.com:/gittest.git
Sending/recieving
git fetch [origin] [master] get files from origin master remote
git pull [origin] [master] fetch from and merge with another repository or a local branch git push otherrepo <branch> stick branch on otherrepo remote
- http://blog.nicoschuele.com/?p=217
- https://stackoverflow.com/questions/15316601/why-is-git-pull-considered-harmful
Reset
git reset --hard HEAD reset any uncommitted changes in Index git reset --hard origin/master reset from remote master
Rebase
Branching and merging
git branch list branches with current starred git branch -a list branches (including remote) git branch <branch> create branch git branch -d <branch> delete branch
git checkout <branch> switch to working on <branch> git checkout -b <branch> same as "git branch <branch> | git checkout <branch>" git checkout -- <file> checkout file from HEAD git checkout - check out previous branch
git checkout HEAD@{1} checkout next commit on current branch
git checkout HEAD~ checkout previous commit on current branch
git merge <branch> merge branch, keep branch in commit log git rebase <branch> - fast-forward merge current to <branch> (?) git diff master <branch> - show difference between master and another branch
git branch --set-upstream master origin/master Branch master set up to track remote branch master from origin.
Stash
Log
git log list commits with message and sha git log . log for current directory git log --since="today" git log --since="6am" git log -p show diffs git log -p -2 show second two last diffs
lol = log --graph --decorate --pretty=oneline --abbrev-commit
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
Diff
See also Vim#Git
git diff diff changes git diff --cached diff changes in staging
git diff shaOfCheckIn show diff between sha and current
git show shaOfCheckIn show diff of sha from previous or git diff shaOfCheckIn^ shaOfCheckIn git diff shaOfCheckIn{^,}
git diff <revision_1>:<file_1> <revision_2>:<file_2> diff between two files
Bisect
Merging
git mergetool git mergetool -t opendiff
Meld GUI is worth checking.
Fugitive
:ls list window numbers
[c jump to previous changeset ]c jump to next changeset
:diffget [window] get change from active window to working
:diffupdate redraw diff highlighting
- Vimcasts.org: a complement to command line git
- Vimcasts.org: resolving merge conflicts with vimdiff
Tags
git tag list repo tags git tag 1.0 <sha> tag <sha> (branch+commit hash) with 1.0
tags point to a sha. use git checkout [tag] to change to the commit.
Submodules
git submodule add git@mygithost:project [--branch x.y] [directory/path] # add submodule and checkout specific branch
git submodule init git submodule update
or
git submodule update --init # bootstrap submodules listed in .gitmodules after cloning somewhere
git submodule foreach git pull origin master # update all submodules
git submodule deinit directory/path # disable a submodule
git rm --cached path/to/submodule # remove a submodule
- Drupal Deployment with Git Submodules
- Use Git submodules to avoid storing Drupal core and contrib modules in your site's repository
- Git Submodules: Adding, Using, Removing, Updating
Patches
git diff > change.patch # create a patch git diff > [description]-[issue-number]-[comment-number].patch # create a Drupal patch git apply -v <patch> # apply patch. also; curl https://github.com/github/jobs/pull/25.patch | git am
.gitignore
- man gitignore - Specifies intentionally untracked files to ignore
- https://github.com/github/gitignore - A Collection of Useful .gitignore Templates
Example to exclude everything except a specific directory foo/bar (note the /* - without the slash, the wildcard would also exclude everything within foo/bar):
$ cat .gitignore # exclude everything except directory foo/bar /* !/foo /foo/* !/foo/bar
* !.gitignore !sxhkd/sxhkdrc !bspwm/* !compton.conf !gtk-2.0/gtkrc-2.0 !/myrepos
Archive to tar
git archive [12] default output is tar git archive master | tar -x -C /somewhere/else pipe to extraction git archive --format=tar --remote=git@server:repo.git master | tar -xf -
also, Legit.
Bundle
git bundle - Move objects and refs by archive
Plumbing
CLI tools
Zsh prompt symbols
Status: ✔: repository clean ●n: there are n staged files ✖n: there are n unmerged files ✚n: there are n changed but unstaged files …: there are some untracked files Branch: ↑n: ahead of remote by n commits ↓n: behind remote by n commits ↓m↑n: branches diverged, other by m commits, yours by n commits :: hash, not a branch
Ncurses
other
GUI
- http://www.kernel.org/pub/software/scm/git/docs/git-gui.html
- http://sourceforge.net/projects/qgit/ - qt
- https://live.gnome.org/giggle - viewer
- http://www.syntevo.com/smartgit/index.html - java
Handy
- git-up - fetch and rebase all locally-tracked remote branches
- SCM Breeze is a set of shell scripts (for bash and zsh) that enhance your interaction with git. It integrates with your shell to give you numbered file shortcuts, a repository index with tab completion, and many other useful features. [13]
- git-export - Export the contents of the current git index to the given destination, ready to rock.
- git pissed tracks any number of words across your entire git history. The defaults are wildly offensive and inspired by Vidar Holen's Linux Kernel Swear Counts.
- http://robots.thoughtbot.com/announcing-gitsh - git shell
Large files
git-annex
GitMedia
LFS
Repository management
- https://git.wiki.kernel.org/index.php/GitHosting
- https://git.wiki.kernel.org/index.php/Interfaces,_frontends,_and_tools#Web_Interfaces
Articles
Git used for private repo, with Gitweb for easy overview.
- https://moocode.com/posts/6-code-your-own-multi-user-private-git-server-in-5-minutes
- http://computercamp.cdwilson.us/git-gitolite-git-daemon-gitweb-setup-on-ubunt
- http://tjworld.net/wiki/Howto/GitPublicRepositoryInstallAndConfigure
git-daemon
- http://git-scm.com/book/en/Git-on-the-Server-Git-Daemon
- http://hype-free.blogspot.co.uk/2011/06/setting-up-git-daemon-under-ubuntu.html
- http://granjow.net/git-read-access.html
- https://srctwig.com/2012/08/16/gitdaemon-troubleshooting/
Gitolite
- create git user
- ~/.ssh/authorized_keys is empty or non-existent
- put pub key in $HOME/YourName.pub
git clone git://github.com/sitaramc/gitolite mkdir -p $HOME/bin gitolite/install -to $HOME/bin gitolite setup -pk YourName.pub
gitolite-admin is only accessible with the public key named after the git account used for the gitolite
- Public read access for git repositories
- git + gitolite + git-daemon + gitweb setup on Ubuntu 11.10 server
GitLab
- GitLab is a free project and repository management application
recommends 1Gb ram!
gerrit
RhodeCode
GitBucket
Gitblit
Gogs
Services
GitHub
Tools
- github-cli - command-line interface to GitHub's Issues API (v2)
- hub is a command-line wrapper for git that makes you better at GitHub.
- willitmerge - A command line tool to check if pull requests are mergeable.
Gist
- https://github.com/defunkt/gist - gists from the commandline
- https://github.com/ConradIrwin/jist - active fork of above with oauth
Related
- GitTorrent - a peer-to-peer network of Git repositories being shared over BitTorrent. You can read more about the project at this blog post. The design of GitTorrent has five components: A "git transport helper" that knows how to download and unpack git objects, and can be used by Git itself to perform a fetch/clone/push. A distributed hash table that advertises which git commits a node is willing to serve. A BitTorrent protocol extension that negotiates sending a packfile with needed objects to a peer. A key/value store on the distributed hash table, used as a "user profile" describing a user's repositories and their latest git hashes. A method for registering friendly usernames on Bitcoin's blockchain, so that a written username can be used to find a user instead of an ugly hex string.
- http://prose.io/ - static site management
- http://gitfm.com - find interesting projects
- Ost.io ("open-source talks") is a forum for open-source projects and the best place for discussing project stuff with other users. It is tightly integrated with GitHub.
- https://github.com/FriendCode/gitrap - forum system
Bitbucket
- https://bitbucket.org - free private repos
N.b. https clone url includes username@, which will require password. remove this for straight-through access.
curl -k -X POST --user user:pass "https://api.bitbucket.org/1.0/repositories" -d "name=project_name"
https://<user>:<pass>@bitbucket.org/<user>/<project>.git
Other
to sort