Git Global Setup
git config --global user.name "Your Name Here" git config --global user.email you@example.com
Git Commands
Common Git Commands
To download a new git repository
(Public access)
git clone http://git.example.com/folder/project.git
Update an exciting repository
(From within the projects folder)
git pull
Comment a change
git comment file.txt
To Revert a comment
git revert ce963c9db00c25b3c1e6add1fe6032aef61a5bed
Commit
Modify the last commit
git commit --amend
Patches
Creating a patch
git diff file_with_changes > 0001-name_of_patch_file.patch gzip 0001-name_of_patch_file.patch
Patching a file or directory
gzip -dc 0001-name_of_patch_file.patch.gz |patch -p1
Branching
Creating a new branch
git branch <branch>
or to create a branch and switch to it
git checkout -b <branch>
Pulling changes from branches
git checkout <branch_committing_to>
Now that your in the branch you want to add the changes to, run:
git pull . <branch_committing_from>
Changing to a different branch
git checkout <branch>
Deleting a branch
git branch -d <branch>
Deleting a remote branch
git push origin :<branch>
Pushing a branch to github
git push <remote_repository_name> <branch_name>
So that would be…
git push origin <branch>
Display branches on github
git remote show origin
Pulling a branch from github
git checkout --track -b <name_of_local_branch> origin/<name_of_remote_branch>
Tagging
Tagging a branch
git tag -a -m "tagging version 1.0" 1.0
Pushing the tag to github
git push --tags
Deleting a tag
git tag -d 1.0
Removing a deleted tag from github
git push origin :refs/tags/1.0
Submodules
To update existing submodules
git pull git submodule init git submodule update
To add a new submodule to a project
git submodule add <remote-host>:<project.git> <project.git>
So if you are adding project “program” from the example git server you will run
git submodule add git://example.com/program.git program
Creating an secure Git remote server
On the Server create the git repository
mkdir name-of-git-repo.git cd name-of-git-repo.git git init --bare
On the Client System create the git repo to import into the server
git init touch README git add README git commit -m 'first commit' git remote add origin git@REMOTE_SERVER:name-of-git-repo.git git push origin master
Importing an SVN repo into git
To import a svn repo create a new git repo and run
git svn clone https://svn.foo.com/svn/proj git commit
- http://tsunanet.blogspot.com/2007/07/learning-git-svn-in-5min.html
- http://djwonk.com/blog/2008/05/09/cleanly-import-svn-repository-into-git/