How to get git configured to work with ssh (github) and commonly used git commands for the terminal.
There are multiple option how to get git installed on your system, and some operating system have it installed by default.
Lets check if git is already installed on your system:
- Open terminal.
- Check the git version:
git --version
If you didn't get a output looking like git version X.X.X
you'll need to install git for your system.
- Open terminal.
- Set git user name & email:
git config --global user.name "Firstname Lastname"
git config --global user.email "firstname.lastname@whatever.io"
- Set git to use new behavior for git push:
git config --global push.default simple
- Generate a ssh key for your device:
ssh-keygen -t ed25519
- Press ENTER (defaults to ~/.ssh/id_ed25519)
- Press ENTER (to skipping password)
- Press ENTER (to skipping password)
- Add ssh key to the ssh-agent:
eval $(ssh-agent) ssh-add ~/.ssh/id_ed25519
- Get the ssh public key:
cat ~/.ssh/id_ed25519.pub
- Copy the output.
- Open browser.
- Go to https://github.com/settings/keys.
- Click New SSH key
- Enter for example device name in the Title field.
- Paste the public key in the Key field.
- Click the Add SSH key.
- Enable SSO for your SSH key (if Single Sign On is activated for your account):
- Open Enable SSO.
- Click Authorize next to your organization.
- Complete the SSO process.
- Return to terminal.
- Test your ssh connection:
ssh -T git@github.com
- If asked for authenticity of host github.com, enter yes.
How you "download" and "update" your local copy of files from the server.
git clone git@git-repo.git
Downloads the content of master branch in the git repository.
git clone -b branch-name git@git-repo.git
Downloads the content of a specific branch in the git repository.
Get latest changes from the server.
How you can contain and group your changes depending on what you're working on.
Lists all branches in your machine.
Creates a branch.
Creates a branch & switches to it.
Switch to a existing branch.
Delete a branch. Make sure you are not checked out on the branch to delete.
How you manage changed files and submit them to the server.
Show changed files and what files has been marked for add.
Adds a file to the staged files list. You may also use patterns to add multiple files, for example src/* to add all files in src folder.
Create a commit to the currently checked out branch.
Pushes the new commits to the server.
Various commands that might be needed from time to time.
Resets all files to the branch initial state (except new files).
Resets all files to the branch initial state.
Removes all untracked files from the file system.