My Git cheat sheet

Ultra-simple git usage:

# Initial 'checkout':
git clone <remote-repository>
 
# Daily process:
cd <local-repository>
git pull
# Make some changes
git add <changed files>
git commit
git push

Setting up a shared git repo:

# Assuming you have an existing project in a git repo called "./project":
mkdir project.git
cd project.git
git --bare init --shared
git --bare fetch ../project master:master
cd ..
scp -r project.git someserver:/some/shared/location
ssh server
sudo chgrp -R group_containing_all_developers /some/shared/location/project.git

Publish branch to remote:

# Create new branch locally:
git branch <branch name>
# Push the branch to the remote repository:
git push origin <branch name>
# Overwrite the local branch with a tracking version:
git branch -f <branch name> origin/<branch name>

Git submodules:

# Add a submodule:
git submodule add <repo> <path>
 
# Cloning a repo with submodules:
git clone <repo>
git submodule init
git submodule update
 
# Updating a project with submodules
git pull
git submodule update

You must be logged in to post a comment.