Stage a file to commit.

#git
git add your-file-name
copy

Stage all modified or new files to commit.

#git
git add .
copy

Appending "-A" flag stages everything including deletions.

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

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

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

Add ssh key to the keychain.

#git#ssh
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.

#git#ssh
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_rsa_example_key
copy

Lists all remote and local branches.

#git#branch
git branch -a
copy

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

#git#stash
git stash apply
copy

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

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

Change url path of the remote repository.

#git#remote
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#ssh
git config -l
copy

Checkout an existing branch by name.

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

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

#git#ssh
git clone repository-address
copy

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

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

Check ssh Github connection.

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

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

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

This command steps you through the ssh key creation.

#git#ssh
ssh-keygen
copy

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

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

Removes all stashed changes.

#git#stash
git stash drop
copy

Start the ssh agent.

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

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

#git
git fetch
copy

Set global config values.

#git
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
git log
copy

Returns full log of file changes including file deletion.

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

Check git version.

#git
git --version
copy

Lists all local branches.

#git#branch
git branch
copy

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

#git
git remote -v
copy

Merge a branch with currently checked out branch.

#git#merge
git merge your-branch-name
copy

Pull all changes from the remote branch.

#git
git pull
copy

Pull changes from all remote branches.

#git
git pull --all
copy

Lists all remote branches including statuses and latest commits.

#git
git branch -v
copy

Lists all remote branches.

#git#branch
git branch -r
copy

Use this command to remove a file from git cache.

#git
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#remove
git rm --cached somedirecory/ -r
copy

Remove a given origin.

#git#origin
git remote rm origin
copy

Unstage all modified or new files from the commit.

#git
git reset .
copy

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

#git
git reset --hard
copy

Unstage a file from the commit.

#git
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#remove
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#branch
git origin --set-upstream your-branch-name
copy

Connect via SSH using a specific key.

#git#ssh
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
git stash
copy

Lists all stashes.

#git#stash
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
git stash pop
copy

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

#git
git status
copy

This command will undo the latest commit.

#git
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.

#git#vim
1. press "i"
2. type in your message
3. press "esc"
4. type ":wq"
5. hit enter
copy
NordVPN NordVPN