Thursday, October 3, 2019

Using Git from the Command Line

This post is more for my future self, but others may find it useful. Feel free to comment if I've made any errors or missed anything important.

Assuming that Git is already installed, to start using it with terminal commands we need to set up a couple of things:

git config --global user.email "INSERT_EMAIL_ADDRESS_HERE"
git config --global user.name "MisterHay"
git config --global core.editor nano

It's also a good idea to set up SSH keys.

and then clone the appropriate repository:

git clone https://github.com/callysto/curriculum-notebooks.git

or with ssh:

git clone git@github.com:callysto/curriculum-notebooks.git

and some useful commands:

list branches:
git branch -a

get files from GitHub:
git checkout origin/staging

create branch from staging:
git checkout origin/staging -b NameOfNewBranch

change to branch (if not already there):
git checkout --track origin/NameOfBranch

edit files, then (stage changes):
git add changed_file.ipynb
or
git add ./*

check with:
git status

discard all local changes to all files permanently:
git reset --hard

commit to local:
git commit

push to remote:
git push -u origin NameOfBranch

then create a pull request to staging from that_branch using GitHub.com interface

To see what has been happening, check the top of
git log

Hopefully that's enough to get you (future me back) up to speed.

No comments: