Helpful Git Commands
Note: Git requires SSH key pair authentication to access remote repositories.
Generate a 2048-bit RSA Encrypted SSH key pair for git and other services secured by SSH.
ssh-keygen -t rsa -b 2048
This should generate a file named id_rsa.pub in your /home/username/.ssh folder. You must copy this key and enter it into your user account for repository hosting services.
Display your Public Key to copy and paste into your Remote Repository Host.
Sites such as Github, Unfuddle, and BitComet require your SSH Public Key to access their repositories. One you have added the key to your account you are ready to commit and clone repositories.
Check your current git identity with the following command.
git config -l
Identify yourself to git with the following commands.
git config --global user.name "Your Name" git config --global user.email firstname.lastname@example.org
git config --global user.name "John Doe" git config --global user.email email@example.com
Please Note: It is best to use your real name and your email address. That way people know commits are coming from you.
Initialize and create a new git repository in a folder with the following command.
Add all files and folders in your git repository folder to the local repository.
git add *
Add a single file to your git repository.
git add filename git add readme.txt
Commit your changes to your local git repository.
git commit -am "explain your commit here."
git commit -am "initial commit"
Add a remote repository to your git repository.
git remote add remote-name git://example.com/username/repository-name.git
git remote add origin git://github.com/sk33lz/zenlike.git
Configure a branch on your remote repository as an upstream server.
git config remote.remote-name.push refs/heads/branch-name:refs/heads/branch-name
git config remote.origin.push refs/heads/master:refs/heads/master
Push your changes to your remote git repository.
git push -u remote-name branch-name
git push -u origin master
Clone a Git repository to your computer or server that can be updated. (Read/Write)
git clone firstname.lastname@example.org:username/repository-name.git
git clone email@example.com:sk33lz/zenlike.git
Clone a Git repository to your computer that cannot be updated. (Read Only)
git clone git://example.com:username/repository-name.git
git clone git://github.com/sk33lz/zenlike.git