Difference between revisions of "Git"

From dankwiki
 
(16 intermediate revisions by the same user not shown)
Line 4: Line 4:
* [http://github.com GitHub] provides pretty reasonable git hosting services; open source projects eat free.
* [http://github.com GitHub] provides pretty reasonable git hosting services; open source projects eat free.
* [http://wiki.github.com/davglass/github-trac github-trac] is a trac extension for working with GitHub
* [http://wiki.github.com/davglass/github-trac github-trac] is a trac extension for working with GitHub
 
* Remote repacks/compressions can consume a great deal of memory. To cap the remote packing at, say, 2G, enter the remote repository and run:
<pre>git config pack.windowMemory 1000m
git config pack.packSizeLimit 2000m</pre>
==Configuration==
==Configuration==
Dump your user configuration with <tt>git config -l</tt>:<pre>[recombinator](129) $ git config -l
Dump your user configuration with <tt>git config -l</tt>:<pre>[recombinator](129) $ git config -l
Line 24: Line 26:
|-
|-
| Add an external repository ''repo'' at point ''dir/path''
| Add an external repository ''repo'' at point ''dir/path''
| <tt>svn propedit svn:ignore dir</tt>, and add <tt>path</tt>
| <tt>svn propedit svn:externals dir</tt>, and add <tt>repo path</tt>
| <tt>git submodule add repo dir/path</tt>
| <tt>git submodule add repo dir/path</tt> (there's a [http://git.wiki.kernel.org/index.php/GitSubmoduleTutorial Submodule Tutorial])
|}
|}
==Recipes==
===Create bare repo from existing files===
We have existing, untracked files at <tt>workpath</tt>. We want to initialize a (possibly remote) bare repository <tt>repo</tt> with the contents of <tt>workpath</tt>.
* In <tt>repo/</tt>, run <tt>git init --bare</tt>
* In <tt>workpath/</tt>, run <tt>git init</tt>
* In <tt>workpath/</tt>, run <tt>git remote add origin repo</tt>
* In <tt>workpath/</tt>, run <tt>git add .</tt>
* In <tt>workpath/</tt>, run <tt>git push</tt>
===Prune remote branches===
<tt>git remote prune origin</tt>
This can be made automatic with <tt>git config remote.origin.prune true</tt> since git 1.8.5.
===Hard sync to upstream===
Warning: this will throw away even committed local changes! Assuming remote <tt>upstream</tt> and branch <tt>master</tt>:
<tt>git reset --hard upstream/master</tt>
then, to force your own fork to match:
<tt>git push origin master --force</tt>
Congratulations! You've just thrown away any local work.
===Remove local+remote tag===
* <tt>git tag -d TAG</tt>
* <tt>git push --delete origin TAG</tt>
===Rename local+remote branch===
Remote branches cannot be renamed in a single step. Instead,
* Check out the remote branch if it is not checked out
* Rename the local branch with <tt>git branch -m newname</tt>
* Delete the remote branch with <tt>git push origin ––delete oldname</tt>
* Re-add and reset the remote branch with <tt>git push origin –u newname</tt>
===Find commit corresponding to tag===
* <tt>git rev-list -n 1 TAG</tt>
===List all commits between two hashes Ce and Cb===
* <tt>git rev-list Ce..Cb</tt>
===Update local list of remote branches===
* <tt>git remote update origin --prune</tt>
==See also==
* [[GitHub]]


==Links==
==Links==
Line 32: Line 80:
* tpope's "[http://www.tpope.net/node/106 Note About Git Commit Messages]" (2008-04-19)
* tpope's "[http://www.tpope.net/node/106 Note About Git Commit Messages]" (2008-04-19)
* GitWiki's [http://git.or.cz/gitwiki/GitTips GitTips]
* GitWiki's [http://git.or.cz/gitwiki/GitTips GitTips]
[[Category:Source Control]]

Latest revision as of 03:10, 6 December 2021

Here's a good crash course for subversion users.

Hosting

  • GitHub provides pretty reasonable git hosting services; open source projects eat free.
  • github-trac is a trac extension for working with GitHub
  • Remote repacks/compressions can consume a great deal of memory. To cap the remote packing at, say, 2G, enter the remote repository and run:
git config pack.windowMemory 1000m
git config pack.packSizeLimit 2000m

Configuration

Dump your user configuration with git config -l:

[recombinator](129) $ git config -l
user.name=Nick Black
user.email=dank@qemfd.net
github.user=dankamongmen
[recombinator](0) $

Dump the system configuration, if one exists, via git config --system -l:

[recombinator](129) $ git config --system -l
color.diff=auto
color.status=auto
color.branch=auto
[recombinator](0) $

Subversion equivs

goal subversion git
Add an external repository repo at point dir/path svn propedit svn:externals dir, and add repo path git submodule add repo dir/path (there's a Submodule Tutorial)

Recipes

Create bare repo from existing files

We have existing, untracked files at workpath. We want to initialize a (possibly remote) bare repository repo with the contents of workpath.

  • In repo/, run git init --bare
  • In workpath/, run git init
  • In workpath/, run git remote add origin repo
  • In workpath/, run git add .
  • In workpath/, run git push

Prune remote branches

git remote prune origin

This can be made automatic with git config remote.origin.prune true since git 1.8.5.

Hard sync to upstream

Warning: this will throw away even committed local changes! Assuming remote upstream and branch master:

git reset --hard upstream/master

then, to force your own fork to match:

git push origin master --force

Congratulations! You've just thrown away any local work.

Remove local+remote tag

  • git tag -d TAG
  • git push --delete origin TAG

Rename local+remote branch

Remote branches cannot be renamed in a single step. Instead,

  • Check out the remote branch if it is not checked out
  • Rename the local branch with git branch -m newname
  • Delete the remote branch with git push origin ––delete oldname
  • Re-add and reset the remote branch with git push origin –u newname

Find commit corresponding to tag

  • git rev-list -n 1 TAG

List all commits between two hashes Ce and Cb

  • git rev-list Ce..Cb

Update local list of remote branches

  • git remote update origin --prune

See also

Links