Skip to content

How to get git configured to work with ssh and basic terminal commands

Notifications You must be signed in to change notification settings

johanwestling/git-going

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 

Repository files navigation

Git going

How to get git configured to work with ssh (github) and commonly used git commands for the terminal.


Installation

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:

  1. Open terminal.
  2. 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.


Configuration

  1. Open terminal.
  2. Set git user name & email:
    git config --global user.name "Firstname Lastname"
    
    git config --global user.email "firstname.lastname@whatever.io"
    
  3. Set git to use new behavior for git push:
    git config --global push.default simple
    
  4. Generate a ssh key for your device:
    ssh-keygen -t ed25519
    
  5. Press ENTER (defaults to ~/.ssh/id_ed25519)
  6. Press ENTER (to skipping password)
  7. Press ENTER (to skipping password)
  8. Add ssh key to the ssh-agent:
    eval $(ssh-agent) ssh-add ~/.ssh/id_ed25519
    
  9. Get the ssh public key:
    cat ~/.ssh/id_ed25519.pub
    
  10. Copy the output.
  11. Open browser.
  12. Go to https://github.com/settings/keys.
  13. Click New SSH key
  14. Enter for example device name in the Title field.
  15. Paste the public key in the Key field.
  16. Click the Add SSH key.
  17. 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.
  18. Return to terminal.
  19. Test your ssh connection:
    ssh -T git@github.com
    
  20. If asked for authenticity of host github.com, enter yes.

Common commands

Clone & pull

How you "download" and "update" your local copy of files from the server.

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.

git pull

Get latest changes from the server.


Branches

How you can contain and group your changes depending on what you're working on.

git branch -a

Lists all branches in your machine.

git branch "new-branch-name"

Creates a branch.

git checkout -b "new-branch-name"

Creates a branch & switches to it.

git checkout "branch-to-checkout"

Switch to a existing branch.

git branch -d "branch-to-delete"

Delete a branch. Make sure you are not checked out on the branch to delete.


Commit & Push

How you manage changed files and submit them to the server.

git status

Show changed files and what files has been marked for add.

git add file-to-add.ext

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.

git commit -m "Short description of what changes you've made"

Create a commit to the currently checked out branch.

git push

Pushes the new commits to the server.


Random

Various commands that might be needed from time to time.

git checkout .

Resets all files to the branch initial state (except new files).

git reset --hard

Resets all files to the branch initial state.

git clean -xdf

Removes all untracked files from the file system.

About

How to get git configured to work with ssh and basic terminal commands

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published