Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

rGunti/HowToGit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

marp _class
true
invert

How To Git

Use git like a pro!

Raphael Guntersweiler [email protected]


What you're learning today:

  • Password-less authentication
  • Command line basics
  • Alternatives to Sourcetree

bg contain brightness:0.75 blur

Password-less authentication

How to authenticate without a password?


Benefits

  • no need for domain password
  • blocked domain account doesn't block you from working

How to setup

  1. Open your Git Bash
  2. Generate your SSH key
$ ssh-keygen

Generating public/private rsa key pair.
Enter file in which to save the key (/home/raphael/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/raphael/.ssh/id_rsa.
Your public key has been saved in /home/raphael/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:0123456789abcdefghijklmnopqrstuvwxyz+-/0123 raphael@machine
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|                 |
|                 |
|                 |
+----[SHA256]-----+

  1. Print and copy your SSH Public Key
$ cat ~/.ssh/id_rsa.pub

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCjWf5lpYZmZDyZ7dGHeyN8YvXDN16HNS3P8cjusKGd
znQXq30B/zv/i5Mv8Is/a1vN2y1pUMw/rPgsRHgUFkE0LzjepdmotEXE4urDaLHJhm2jy14I4jvTghdL
7kZrU0Vmu6tXuo7PUG1pCk1psknb3veM1gR0/Ty3gnvsiTYQor8V94pYhMfbwuE30ZRT87K8iNBPI488
DpQEJ+g1L+Fi495BQh98EOgZWmxIe1gJePwIGKjQYbDSQ4nV9vlaloG+oWqU0AiBJ8fHs4I+rFGo64q2
6VWOEiJhOPO95DTpSk38r6lm7Tf65RR0JsCZ1kfPqiANGJQ6SV2/ZQY9cADX raphael@machine

  1. Open your Bitbucket profile and add your SSH public key.

w:600 w:500


  1. Change your existing repositories remote to SSH.
$ git remote set-url origin <SSH URL>
  1. Test your change
$ git pull

Already up to date.

bg contain brightness:0.75 blur

Command Line Basics

yes, I know the stock image shows HTML code


Simple Bash Basics

Navigation and file system

Change directory

$ cd <dir>

List files

$ ls
# or with more details
$ ls -la

Create directory

mkdir <dirname>

Print file content

Print complete file content

$ cat <file>
# or with paging support
$ less <file>

Print first / last 10 lines of a file

$ head <file>
$ tail <file>

Modifying file system

Create an empty file

$ touch <file>

Copy file

$ cp <file> <newFile>

Rename / move file

$ mv <oldFile> <newFile>

Delete file (Note: no Recycle Bin here!)

$ rm <file>
$ rm -rf <directory>

Terminal Interaction

Clear console output

$ clear

Edit a file in the terminal

$ nano <file>
# or if you feel brave (or have no other choice)
$ vi <file>

Helpful hint for vi/vim: You leave the editor by typing :q!


Clone a repository

$ git clone <Repo URL>

Cloning into 'my-cool-repo'...
remote: Enumerating objects: 12, done.
remote: Total 12 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (12/12), done.

Create changes

Add a file

$ git add file.txt

Stage a file for commit

$ git stage file.txt

Commit staged files

$ git commit -m "Your Commit Message"

Check your repos status

$ git status

On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   file.txt

"Unstage" a file

$ git reset file.txt

Sync your changes

Push your changes

$ git push

Pull changes from remote

$ git pull

Fetch changes (without downloading them)

$ git fetch

Reset all changes

Deletes all local changes and returns to the last commit

$ git reset --hard HEAD

List all files to be cleaned

$ git clean -d -n -X

Actually clean the files

$ git clean -d -f -X

Branches

List all branches

$ git branch

Create and check out an existing branch

$ git checkout -b <branch>

Check out an existing branch

$ git checkout <branch>

Check out a remote branch

$ git checkout -b <branch> <remote>/<branch>
# e.g.
$ git checkout -b my-branch origin/my-branch

bg brightness:0.75 blur

Alternative GUI Clients

Because command lines can get exhausting at times


Git GUI (Windows, Mac, Linux)

bg right contain

Pro

  • Simple
  • Already integrated with Git installation

Con

  • Visually clunky
  • Doesn't "hold your hand" at all (=> everything is DIY)

GitKraken (Windows, Mac, Linux)

bg right contain

Pro

  • Modern looking
  • Supports multiple repositories (tabs)
  • Installs into User profile (no admin required)

Con

  • Free edition not permitted for commercial use
  • Use requires a GitKraken account

Fork (Windows, Mac)

bg right contain

Pro

  • Clean and simple structure
  • Quick Launch (type your action)
  • Also installs into User profile
  • Issue tracker link (e.g. JIRA tickets)
  • Free!

Con

  • honestly, I couldn't come up with anything (yet)

More clients?

https://git-scm.com/downloads/guis/

or ask your local search engine of choice


bg brightness:0.75 blur

And don't forget your IDE!


VS Code

bg right contain

  • Integration works great for the normal workflow

  • If you use VS Code to do your work, use it!

  • Note: Most commands are best issued through the command palette (F1)


Visual Studio

bg right contain

  • Integration (called "Team Explorer") is simple and works well enough for most tasks
  • VS2017 works well, VS2019 finally supports stashing
  • Conflict resolution is excellent

Rider (IntelliJ IDEA)

bg right contain

  • Line-wise commiting
  • Change lists (put your changes into a "playlist")
  • Conflict resolution is also excellent
  • If you use Rider (or any Jetbrains IDE), use it!

Any questions?

bg right contain


Thank you for your attention!

Raphael Guntersweiler [email protected]

About

A How To on Git

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published