Git

From Flo's Knowledge in a Nutshell

Jump to: navigation, search

Contents

References

Useful git tricks

Configure Username

git config --global user.name "My Name"
git config --global user.email “My EMail”

Auto Color Output

git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto
git config --global color.interactive auto

Git using sshfs

I use git sometimes over sshfs on a shared hosting without git installed. I noticed that I have to mount the path with the parameter "oworkaround=rename"

sshfs -oworkaround=rename user@remote:/my/remote/path mountpoint/

Using Git

Remove Remote Branch

git push {repo} :heads/{branch}

Eg:

git push origin :somebranch

Commit Uncommitet Changes into new Branch

git-checkout -m -b new_branch
git-commit -am "hello world"

Merge a single commit from a foreign branch into local branch

# Merge in a single commit.
#The -n option tells Git to not commit when it’s finished the merge.
# This allows us to review and commit the changes with our own message later.
# The default commit message is very ambiguous.
$ git cherry-pick -n [The commit’s SHA-1 Hash]

# Review the changes
$ git diff –cached

# Commit the changes after reviewed them
# ..with a nice, human written commit message that makes sense.
$ git commit -a -m “Your commit message (some SHA-1 Hash as a reference)”

Split git archive into two independant archives

Clone the Repo (ABC is the new one)

git clone --no-hardlinks /XYZ /ABC

Remove all from archive except ABC

git filter-branch --subdirectory-filter ABC HEAD

Reset

git reset --hard

Do some cleanup

git gc --aggressive
git prune

Undo git add

Sometimes you added to much files with

git add .

to your repository. You can easily undo this with the command

git rm -r --cached .
Retrieved from "http://wiki.combatx.net/Git"
Personal tools