Difference between revisions of "Git"

From Vague Hope Wiki
Jump to: navigation, search
(Branches)
Line 122: Line 122:
 
git push --force
 
git push --force
 
</pre>
 
</pre>
 +
 +
== Split dir to new project ==
 +
 +
<pre>
 +
cp -r repo repo-submod
 +
cd repo-submod
 +
git filter-branch --subdirectory-filter submod -- --all
 +
</pre>
 +
 +
* http://stackoverflow.com/questions/811251/how-can-i-move-a-single-directory-from-a-git-repository-to-a-new-repository-whil
  
 
== References ==
 
== References ==

Revision as of 06:44, 21 April 2013

See also: Git-svn

Commands I keep forgetting

Un-stage (inverse of add):

git reset file

Update workspace (works for github): (Or better still, use rebase pattern described below.)

git fetch
git merge origin/master

Tags:

git fetch -t upstream
git push --tags

Reset working copy:

git clean -fdx
git checkout .

Branches

New branch from a tag:

git checkout -b newbranch v1.0

Take uncommitted changes to a new branch.

git checkout -b new_branch

Push new branch

git push -u origin new_branch

Switch branches:

git checkout existing_branch

Reset branch

git fetch origin
git reset --hard origin/master

Get branch from remote workspace:

git remote add hostdesu ssh://user@hostdesu/Users/user/development/projectdesu

Pull remote branch and check out:

git checkout --track origin/branch_name

Rebase pattern

TODO: personally test this sequence.

Check out branch we want to (eventually) deliver to. Double check its all up to date.

git checkout desuapp-codefoo
git pull

Create new branch and check out.

git checkout -b task101
  • ( Do actual work, make commits, etc. )

Update local copy of branch we want to deliver to.

git fetch origin

Do the magic rebase thing - rewrite history and send current target branch back in time.

git rebase origin/desuapp-codefoo

Switch to the branch we want to deliver to and get it up to date.

git checkout desuapp-codefoo
git pull

Bring over our work in to the local copy of the delivery target branch.

git rebase task101
  • ( Verify the differences between local and remote copies )

Send it out into the big wide world with the happy satisfaction of a job well done.

git push

Remove directory from history

git filter-branch --tree-filter 'rm -rf com.example.foo' HEAD
rm -rf .git/refs/original/
rm -rf .git/logs/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now
git push --force

Split dir to new project

cp -r repo repo-submod
cd repo-submod
git filter-branch --subdirectory-filter submod -- --all

References

Merge / Rebase

Deploying