add a single file
Stage a file to commit.
git add your-file-name
copy
Stage a file to commit.
git add your-file-name
copy
Stage all modified or new files to commit.
git add .
copy
Appending "-A" flag stages everything including deletions.
git add -A // All changes including deletions
copy
Creates a new branch based of the one currently checked out.
git branch new-branch-name
copy
Add ssh key to the keychain.
ssh-add -K ~/.ssh/id_rsa
copy
If you use multiple accounts on different hosts you may need to add your keys manually at the start of the session. The first line in the example starts the shh agent. The second adds a specific key to the keychain. Make sure to update path to point to your key.
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_rsa_example_key
copy
Lists all remote and local branches.
git branch -a
copy
Applies stashed changes to your local branch without dropping the stash.
git stash apply
copy
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
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
This command lists your git settings.
git config -l
copy
Checkout an existing branch by name.
git checkout your-branch-name
copy
Copy remote repository in to the current folder. Use repository web address or ssh key.
git clone repository-address
copy
Commits checked-in changes to the local working branch with a message in one command.
git commit -m "Message describing committed changes."
copy
Check ssh Github connection.
ssh -T git@github.com
copy
With this single command you create and checkout a new branch.
git checkout -b new-branch-name
copy
This command steps you through the ssh key creation.
ssh-keygen
copy
This command will create a new key using a more streamlined approach.
ssh-keygen -t rsa -C "youremail@address.com"
copy
Removes all stashed changes.
git stash drop
copy
Start the ssh agent.
eval $(ssh-agent -s)
copy
Allows you to check for remote branch changes without affecting or updating the local files.
git fetch
copy
Set global config values.
git config --global user.name "NewUsername"
copy
Git log returns a list of all commits including SHA-1 checksum, author, date and the commit message.
git log
copy
Returns full log of file changes including file deletion.
git log --full-history -- file/path.html
copy
Check git version.
git --version
copy
Lists all local branches.
git branch
copy
This command will list all remote branches. Useful if you want to push changes to multiple repositories.
git remote -v
copy
Merge a branch with currently checked out branch.
git merge your-branch-name
copy
Pull all changes from the remote branch.
git pull
copy
Pull changes from all remote branches.
git pull --all
copy
Lists all remote branches including statuses and latest commits.
git branch -v
copy
Lists all remote branches.
git branch -r
copy
Use this command to remove a file from git cache.
git rm --cached path/to/your/file.html
copy
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
Remove a given origin.
git remote rm origin
copy
Unstage all modified or new files from the commit.
git reset .
copy
Unstage all uncommited changes. This command will also remove all uncommited files!
git reset --hard
copy
Unstage a file from the commit.
git reset your-file-name
copy
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
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
Unstage all modified or new files from the last commit. It will not remove any files or changes.
git reset --soft HEAD~1
copy
Connect via SSH using a specific key.
ssh -i ~/.ssh/id_rsa_customkey user@111.22.33.444
copy
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
Lists all stashes.
git stash list
copy
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
Shows the status of your checked out branch and lists all modified files.
git status
copy
This command will undo the latest commit.
git reset --soft HEAD~1
copy
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