Git and Github on OSX and Ubuntu

March 29, 2021

Georgia Mountains

install github CLI on osx

copy
brew install gh
brew upgrade gh
gh auth login --web
# for headless:
# gh auth login --with-token
# echo "token" | gh auth login --with-token

https://cli.github.com/manual/installation

install github CLI on linux ubuntu

https://github.com/cli/cli/blob/trunk/docs/install_linux.md

set github tokens to login to github via cli

https://github.com/settings/tokens/new

create local git repo and github project

copy
# change to your github account username:
GH_USER="changeme-github-account-username"
# set current dirname as project name
GH_NAME=`basename "\`pwd\`"`
touch README.md
git init
git add .
# Adds the files in the local rep and stages them for commit. To unstage a file, use 'git reset HEAD YOUR-FILE'.
git commit -m "init"
# create a repository under your account using the current directory name
gh repo create $GH_NAME --private
#wait a while
sleep 2
git branch -M main
git push -u origin main
echo https://github.com/$GH_USER/$GH_NAME

create local repo

copy
git init
git add .
# Adds the files in the local rep and stages them for commit. To unstage a file, use 'git reset HEAD YOUR-FILE'.
git commit -m "init"

add remote to github

copy
git remote add origin  <REMOTE_URL> 
# Sets the new remote
git remote -v
# Verifies the new remote URL

push to github

copy
$ git push -u origin main
# Pushes the changes in your local repository up to the remote repository you specified as the origin

create git repo and add to existing github project

copy
touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:username/reponame.git
git push -u origin master

© 2021 sebbie.pl