Differences between revisions 1 and 12 (spanning 11 versions)
Revision 1 as of 2010-08-11 22:48:22
Size: 290
Editor: SamatJain
Comment:
Revision 12 as of 2017-05-11 20:34:29
Size: 2493
Editor: SamatJain
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
[[https://wikileaks.org/ciav7p1/cms/page_1179773.html|CIA's git tips & tricks]] sheet is interesting, and oddly similar to this one.

== Workflow for gitorious and github ==

Initial checkout:

{{{#!highlight sh
# Fork repo on gitorious/github
# Pull repo from gitorious/github
# Add remote for upstream, e.g.
cd Spoon-Knife
git remote add upstream git://github.com/octocat/Spoon-Knife.git
git fetch upstream
}}}

When needing to merge upstream changes back into master:

{{{#!highlight sh
# Make sure we're in the branch we want to be in (i.e. master)
git checkout master
git fetch upstream
# Merge from master branch of upstream into current branch
git merge upstream/master
}}}

== Cookbook ==

=== Delete remote branch ===

{{{#!highlight sh numbers=off
git push origin :name-of-remote-branch
}}}

=== Reverting changes ===

Amend the previous commit that has not been propogated (i.e. undo it, then start a new one with the pending changes in the index):

{{{
git commit --amend -a -m "New commit message"
}}}
Line 2: Line 43:

{{{
git reset --soft HEAD^
}}}

just changes the repository without changing the files you've edited on disk. However:
Line 7: Line 54:
For a commit that has been propagated, there is no way to undo. However, the following will create a new commit undoing the previous commit's changes: will reset both repository and revert files.

Once
a commit that has been propagated, there is no way to undo. However, the following will create a new commit undoing the previous commit's changes:
Line 12: Line 61:

=== Pull with rebase instead of merge ===

{{{
git pull --rebase
}}}

Configure a branch to always do a rebase instead of a merge:

{{{
git config branch.master.rebase true
}}}

=== Enforce .gitignore ===

Remove files from the repository that should have been ignored by .gitignore:

{{{
git rm -r --cached .
git add .
git status
git commit -m ".gitignore is now working"
}}}

=== Ignore whitespace bullshit ===

{{{
# Ignore white space when pulling or merging
git pull -Xignore-space-change
git merge -Xignore-space-change

# Ignore white space changes when diff'ing
git diff --ignore-space-change
}}}

== Per-repository user settings ==

{{{#!highlight sh numbers=off
git config user.name 'Samat K Jain'
git config user.email 'nobody@example.com'
}}}

== Interesting reading ==

[[http://tom.preston-werner.com/2009/05/19/the-git-parable.html|The Git Parable]]: Describes building a system like git, from the ground-up

CIA's git tips & tricks sheet is interesting, and oddly similar to this one.

Workflow for gitorious and github

Initial checkout:

   1 # Fork repo on gitorious/github
   2 # Pull repo from gitorious/github
   3 # Add remote for upstream, e.g.
   4 cd Spoon-Knife
   5 git remote add upstream git://github.com/octocat/Spoon-Knife.git
   6 git fetch upstream

When needing to merge upstream changes back into master:

   1 # Make sure we're in the branch we want to be in (i.e. master)
   2 git checkout master
   3 git fetch upstream
   4 # Merge from master branch of upstream into current branch
   5 git merge upstream/master

Cookbook

Delete remote branch

git push origin :name-of-remote-branch

Reverting changes

Amend the previous commit that has not been propogated (i.e. undo it, then start a new one with the pending changes in the index):

git commit --amend -a -m "New commit message"

Undo a commit that has not been propagated:

git reset --soft HEAD^

just changes the repository without changing the files you've edited on disk. However:

git reset --hard HEAD^

will reset both repository and revert files.

Once a commit that has been propagated, there is no way to undo. However, the following will create a new commit undoing the previous commit's changes:

git revert HEAD

Pull with rebase instead of merge

git pull --rebase

Configure a branch to always do a rebase instead of a merge:

git config branch.master.rebase true

Enforce .gitignore

Remove files from the repository that should have been ignored by .gitignore:

git rm -r --cached .
git add .
git status
git commit -m ".gitignore is now working"

Ignore whitespace bullshit

# Ignore white space when pulling or merging
git pull -Xignore-space-change
git merge -Xignore-space-change

# Ignore white space changes when diff'ing
git diff --ignore-space-change

Per-repository user settings

git config user.name 'Samat K Jain'
git config user.email 'nobody@example.com'

Interesting reading

The Git Parable: Describes building a system like git, from the ground-up


CategoryCheatSheet

SamatsWiki: CheatSheet/Git (last edited 2023-03-01 08:30:42 by SamatJain)