Commit Your Code From the Command Line with Git

This article outlines how to commit your code to git and push it to GitHub. The process is quite simple and you should get in the habit of doing it whenever you are done coding for the day.

Procedure

  1. Log on to Azure Notebooks: https://notebooks.azure.com with your SU email and NetID password.
  2. Select the IST256 project from the My Projects workspace.
  3. Click the Terminal icon to launch the terminal.
    When the terminal launches you should see a command line with the prompt nbuser@nbserver:~$
  4. Switch the current working directory to the library folder by typing:
    cd ~/library
  5. Your command prompt should now read: nbuser@nbserver:~/library$
    Next you need to switch into the local copy of your Git reposiotry folder. This will likely begin with the year and semester you’re taking the course e.g. 2019-fall-learn-python-mafudge-su. For example, I would type: cd 2019-fall-learn-python-mafudge-su. The easiest way to find your folder is to type: cd then type the year you’re taking the course, then press the TAB key and the teriminal will complete the rest for you!
  6. From the nbuser@nbserver:~/library/your-repository-folder$ prompt, you can verify you are in the right place by typing:
    git status
    If somewhere in the output, it says fatal: not a git repository then you are not in the right place!
    If somewhere in the output it says on branch master then you are in your git repository folder.
  7. To track the changes you’ve made to the files type:
    git add --all.
  8. To commit a save point to git of your work, type:
    git commit -m "message" where message is your commit message. It should reflect the type of work you did this session, like completed lab 3 or finished NYC 3.4 for example.
  9. To send your changes to GitHub, type:
    git push origin master

Summary of Git Commands

  • git status
    Checks if you are in the right place and, of course gets the status of the files in your git repository folder. When in doubt, type this command and read the output. It will suggest what to do next!
  • git add --all
    Tracks all the changes you made so they can be commited.
  • git commit -m "message
    Commits the tracked changes under message message. It is important to choose a good commit message that reflects the work you’ve done. The messages show up in Github.
  • git push origin master
    Sends your commits to GitHub.