How to git (and github)

Friday, Apr 17, 2020
Howto git

Version control is important. Git is powerful and GitHub makes it easy to get your project out on the web. My workflow is (uses hub to carry out Github work from command line too):

  1. Create a project directory, add .gitignore and
  2. Initialize git
git init
  1. Add files
git add .
  1. First commit
git commit -m "To begin, begin."
  1. Create a new Github repository with the same name as current directory
hub create
  1. Push local changes to Github
git push -u origin HEAD
  1. Think of a problem to fix or feature to add. Create and checkout a branch to work on that problem
git checkout -b fixOrAddSomething
  1. Stage the files created/changed to solve the problem
git add --all
  1. Commit the files
git commit -m "fixed or added something"
  1. Switch to master
git branch master
  1. Merge changes from branch to master
git merge fixOrAddSomething
  1. Push changes to Github
git push origin master
  1. Take a break
  2. Go back to step 7 and have fun!

Other useful commands

git add file(s)           // add specific files
git add -u                // add all modified files
git log                   // check log
git branch                // list all branches and active branch
git branch -d someBranch  // delete a branch
git reset HEAD someFile   // unstage a file