#git

Stage a file to commit.

git add your-file-name
copy
#git

Stage all modified or new files to commit.

git add .
copy
#git

Appending "-A" flag stages everything including deletions.

git add -A  // All changes including deletions 
copy
#git#branch

Creates a new branch based of the one currently checked out.

git branch new-branch-name
copy
#git#ssh

Add ssh key to the keychain.

ssh-add -K ~/.ssh/id_rsa
copy
#git#branch

Lists all remote and local branches.

git branch -a
copy
#git#stash

Applies stashed changes to your local branch without dropping the stash.

git stash apply
copy
#git

You can create a new branch from any previous commit by running the following code.

git branch new-branch-name {SHA-1 checksum of a commit}
copy
#git#remote

Change url path of the remote repository.

git remote set-url [remote-name] [repository-url]

// i.e.

git remote set-url origin git@github.com:proochster/shortcode.git
copy
#git#ssh

This command lists your git settings.

git config -l
copy
#git#branch

Checkout an existing branch by name.

git checkout your-branch-name
copy
#git#ssh

Copy remote repository in to the current folder. Use repository web address or ssh key.

git clone repository-address
copy
#git

Commits checked-in changes to the local working branch with a message in one command.

git commit -m "Message describing committed changes."
copy
#git#ssh#github

Check ssh Github connection.

ssh -T git@github.com
copy
#git#branch

With this single command you create and checkout a new branch.

git checkout -b new-branch-name
copy
#git#ssh

This command steps you through the ssh key creation.

ssh-keygen
copy
#git#ssh

This command will create a new key using a more streamlined approach.

ssh-keygen -t rsa -C "youremail@address.com"
copy
#git#stash

Removes all stashed changes.

git stash drop
copy
#git#ssh

Start the ssh agent.

eval $(ssh-agent -s)
copy
#git

Allows you to check for remote branch changes without affecting or updating the local files.

git fetch
copy
#git

Set global config values.

git config --global user.name "NewUsername"
copy
#git

Git log returns a list of all commits including SHA-1 checksum, author, date and the commit message.

git log
copy
#git

Returns full log of file changes including file deletion.

git log --full-history  -- file/path.html
copy
#git

Check git version.

git --version
copy
#git#branch

Lists all local branches.

git branch
copy
#git

This command will list all remote branches. Useful if you want to push changes to multiple repositories.

git remote -v
copy
#git#merge

Merge a branch with currently checked out branch.

git merge your-branch-name
copy
#git

Pull all changes from the remote branch.

git pull
copy
#git

Pull changes from all remote branches.

git pull --all
copy
#git

Lists all remote branches including statuses and latest commits.

git branch -v
copy
#git#branch

Lists all remote branches.

git branch -r
copy
#git#remove

This command will stop git from tracking a directory but it will not delete the files from the file system. -r flag (recursive) instructs git to remove all files in the direcory.

git rm --cached somedirecory/ -r
copy
#git#origin

Remove a given origin.

git remote rm origin
copy
#git

Unstage all modified or new files from the commit.

git reset .
copy
#git

Unstage all uncommited changes. This command will also remove all uncommited files!

git reset --hard
copy
#git

Unstage a file from the commit.

git reset your-file-name
copy
#git#remove

This command will stop git from tracking a file but it will not remove the file from the file system.

git rm --cached file-name.html
copy
#git#branch

Creates a remote equivalent of the local branch. This only needs to be done once before or with the initial push of the local branch.

git origin --set-upstream your-branch-name
copy
#git#ssh

Connect via SSH using a specific key.

ssh -i ~/.ssh/id_rsa_customkey user@111.22.33.444
copy
#git#stash

Puts local changes in to stash. They don't get committed to the branch so it's useful for saving your work in progress.

git stash
copy
#git#stash

Lists all stashes.

git stash list
copy
#git#stash

If possible it will apply the changes from the stash to your local branch and then will drop the stash. It equals to running 'git apply' and 'git drop' in sequence.

git stash pop
copy
#git

Shows the status of your checked out branch and lists all modified files.

git status
copy
#git

This command will undo the latest commit.

git reset --soft HEAD~1
copy
#git#vim

Git uses Vim as the default editor. While merging changes Git can asks you to submit a message using Vim editor.

1. press "i"
2. type in your message
3. press "esc"
4. type ":wq"
5. hit enter
copy
Sitemap Git repository