Willem Hoek

Most common Git commands

Jan 01, 2020

Basic commands

Start new repository (‘repo’) either by cloning from remote (e.g. GitHub) or turn any directory into a git repo.

git clone REPO_NAME     # copy repo from remote 
git init                # turns any directory into git repo

Add changes to staging area (Index), commit to local and push to remote.

git add .               # 'stage' is same as 'add'
git commit -m "notes"   # save changes to local repo
git push               

Get updates from remote (pull) and restore local tree

git pull                # update local repo
git restore *           # restore all files to current local repo

Other

git clean -n            # -n Show what will be deleted, -i Interactive, -f Force
git clean -i            # Remove untracked files from the working tree, -i is interactive
git reset               # remove all files from stage
git branch

git status              # overall status, start here if not sure what is going on... 
git log
git log --oneline       # shorter version
git revert XXXXXX       # revert all or some files to previous version


git config --global user.name "Your name" 
git config --global user.email your@email.com 

sample

GitHub: Managing SSH keys

On Windows. When using git with GitHub – you can set up your SSH keys to avoid typing in your GitHub username/password when working on your own repos:

To see if it all work, try this after adding key ssh -vT git@github.com

GitHub: Personal Access token

Support for password authentication was removed. Please use a personal access token instead.

https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/

https://stackoverflow.com/questions/68775869/

https://newbedev.com/where-to-store-the-personal-access-token-from-github

References

[1] Pro Git
The entire Pro Git book, written by Scott Chacon and Ben Straub is available online
https://git-scm.com/book/en/v2 - Accessed 2020-03-11

Related Posts

Solving the Jane Street puzzle of December 2022

Why I created Scrumdog - a program to download Jira Issues to a local database

Jane Street puzzle Feb 2021 SOLVED! OCaml to the rescue

Solving the Jane Street puzzle of Dec 2020 - Backtracking with OCaml

Automate your Jira reporting with Python and Excel

Solving the Jane Street Puzzle of June 2020; Circle Time