Git quick-start basics

Hi there you are reading my Git notes for a basic quickstart Git demo flow, I intend to cleanup in the future but in the meantime feel free to look-around and let me know if you have any doubts.

Git starts with the branch “Master” by default (when you create a new repository)

Git has 3 states:

  1. Working directory (local folder)
  2. Staging (Git index) temporary space
  3. Commit (.git folder) repository, changes history

You can add a 4 state the “Remote”

Windows install

  • git-scm.com

Mac (already installed in latest Mac), probably best to install Xcode first

  •  git version
    git version 2.15.2 (Apple Git-101.1)

 

Ok… so lets get started:

  • Login to GitHub and create a new repository
  • Get the HTTS address to clone it i.e.
    https://github.com/josware/github-demo.git

 

  • $ cd github-demo/
  • $ ls
    README.md
  • $ cat README.md
    # github-demo
    Another simple demo repository to show the basic Git workflow
  • $ git status
    On branch master
    Your branch is up to date with ‘origin/master’.
    nothing to commit, working tree clean

Origin (Git automatically sets a relationship with GitHub and says it’s up to date)
It also says that our working directory is clean

  • $ echo “Just a dummy file to demo Git’s file tracking” >> start.txt
  • $ git status
    On branch master
    Your branch is up to date with ‘origin/master’.
    Untracked files:
      (use “git add <file>…” to include in what will be committed)
    start.txt
    nothing added to commit but untracked files present (use “git add” to track)

Git complains the added file is untracked
Lets add it to staging area:

  • $ git add start.txt
  • $ git status
    On branch master
    Your branch is up to date with ‘origin/master’.
    Changes to be committed:
      (use “git reset HEAD <file>…” to unstage)
    new file:   start.txt

Now the file is waiting to be commited (no changes into the repository {history of commits})
Saging area is designed so you can make changes without affecting the Commits history and can be added as a single atomic unique (all changes at once to a commit)

Ok lets commit it to local repository using git commit -m (m stands for message)

git commit -help

usage: git commit [<options>] [–] <pathspec>…

  •     -q, –quiet           suppress summary after successful commit
  •     -v, –verbose         show diff in commit message template

Commit message options

  •     -F, –file <file>     read message from file
  •     –author <author>     override author for commit
  •     –date <date>         override date for commit
  •     -m, –message <message>
  •                           commit message
  •     -c, –reedit-message <commit>
  •                           reuse and edit message from specified commit
  •     -C, –reuse-message <commit>
  •                           reuse message from specified commit
  •     –fixup <commit>      use autosquash formatted message to fixup specified commit
  •     –squash <commit>     use autosquash formatted message to squash specified commit
  •     –reset-author        the commit is authored by me now (used with -C/-c/–amend)
  •     -s, –signoff         add Signed-off-by:
  •     -t, –template <file>
  •                           use specified template file
  •     -e, –edit            force edit of commit
  •     –cleanup <default>   how to strip spaces and #comments from message
  •     –status              include status in commit message template
  •     -S, –gpg-sign[=<key-id>]
  •                           GPG sign commit

Commit contents options

  •     -a, –all             commit all changed files
  •     -i, –include         add specified files to index for commit
  •     –interactive         interactively add files
  •     -p, –patch           interactively add changes
  •     -o, –only            commit only specified files
  •     -n, –no-verify       bypass pre-commit and commit-msg hooks
  •     –dry-run             show what would be committed
  •     –short               show status concisely
  •     –branch              show branch information
  •     –porcelain           machine-readable output
  •     –long                show status in long format (default)
  •     -z, –null            terminate entries with NUL
  •     –amend               amend previous commit
  •     –no-post-rewrite     bypass post-rewrite hook
  •     -u, –untracked-files[=<mode>]
                              show untracked files, optional modes: all, normal, no. (Default: all)

git commit -m “Adding start.txt to demo our first commit”

  • [master 588d417] Adding start.txt to demo our first commit
    1 file changed, 1 insertion(+)
    create mode 100644 start.txt
    dhcp-10-159-135-46:github-demo jos$ git status
    On branch master
  • Your branch is ahead of ‘origin/master’ by 1 commit.
      (use “git push” to publish your local commits)
    nothing to commit, working tree clean

So now the changes (in this case just one file):

  • Has been moved from stage to the repository
  • We are notified that our local branch is ahead of origin/master by 1 commit
  • Our working tree is clean

Now let’s sync or local and remote repository with the push command:

  • git push origin master
    • origin : destination repository (in this case https://github.com/josware/github-demo.git)
      automatically configured when we used git clone command
    • master : destination branch
      as we mention at the begining, Git initializes the repository with just one branch named master

 

  • $git push origin master
    Counting objects: 3, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 342 bytes | 342.00 KiB/s, done.
    Total 3 (delta 0), reused 0 (delta 0)
    To https://github.com/josware/github-demo.git
       504c785..588d417  master -> master

With this we complete the basics of a Git flow

Bonus, configuring textmate2 as default editor:

  • Install textmate2 (Mac) https://macromates.com/download
    • Open preferences and install shell support
  • Now integrate it with Git:
    • $git config –global core.editor “mate -w”
    • $ git config –global -e
      This should open textmate

How to run Java in “unsafe” mode in Safari 11 ?

Unable to read a notification from SAT Buzon Tributario because you can’t sign it?

I was hitting this issue: received a notification from SAT (Mexico IRS) which as you can imagine may be a big deal, the problem is to read it you need to digitally sign it… and the app was not founding anything on my mac’s file system.

So after a while I realized it may be that Safari was blocking it… and yes it was, you need to run the site in “unsafe mode”

The problem is to do so you need to do an obscure (at least to me) Safari trick I found in this page:

  • https://campus.barracuda.com/product/sslvpn/doc/41093245/how-to-run-java-in-unsafe-mode-for-macos/

Adding this post as it’s not obvious the relationshipt between SAT (Mexican IRS) and this security setting.

Solution in a nutshell:

  • Safari Preferences, Websites, Plug-ins, Java
  • Hold Alt (or Option), click the drop down menu next to the URL (sat.gob.mx), and select Run in Safe Mode.
  • Voila

UnsatisfiableError: The following specifications were found to be in conflict: keras pil

>conda install -c anaconda pil
Solving environment: failed

UnsatisfiableError: The following specifications were found to be in conflict:
– keras
– pil
Use “conda info <package>” to see the dependencies for each package.

 

Workaround: conda install pillow

“Pillow is the “friendly PIL fork” by Alex Clark and Contributors. PIL is the Python Imaging Library by Fredrik Lundh and Contributors. ”
https://qiita.com/YankeeDeltaBravo225/items/6968c376a491b6171671

How to install Tensorflow in an Anaconda virtual environment – Mac

So I have Anaconda installed and wanted to install TensorFlow as well (I’m using PyCharm):

I tried installing TensorFlow with Conda as per official doc:
https://www.tensorflow.org/install/install_mac#installing_with_anaconda

  • conda create -n tensorflow pip python=3.6
  • source activate tensorflow
  • pip install –ignore-installed –upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.8.0-py3-none-any.whl

However when creating a new virtual environment in PyCharm you need to make sure TensorFlow is installed as well in there, to do so simple do (after you have created your project {i.e. tf_basics} in PyCharm):

  • source activate tf_basics
  • pip install –ignore-installed –upgrade $URL_THAT_MAKES_SENSE I used:
    • pip install –ignore-installed –upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.8.0-py3-none-any.whl
    • Tip: you may get annoying messages like: “Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA”
    • Installing the proper tf version should fix it, take a look here for more info: https://github.com/lakshayg/tensorflow-build
    • Or just do…
      import os
      os.environ[‘TF_CPP_MIN_LOG_LEVEL’] = ‘2’

To test your virtual env is running TensorFlow you can run TensorFlow hello world:

import tensorflow as tf
hello = tf.constant(‘Hello, TensorFlow!’)
sess = tf.Session()
print(sess.run(hello))

 

 

How to add you xcode project to github

So you created a brand new xcode project and selected a local repository and are wondering how to add it to github?

Fear not, below steps to make it happen:

Summary:

  1. Navigate to the path of your xcode project and run:
    git remote add foodTracker https://github.com/ACCOUNT/REPOSITORY
  2. Pull the changes
    Git will complain of “fatal: refusing to merge unrelated histories”  solution”–allow-unrelated-histories” use the option
    git pull REPOSITORY master –allow-unrelated-histories
  3. Now you should be able to push from xcode

Other useful commands:

  • git show remote
  • git remote remove REPOSITORY

Happy coding!

Checking what your Mac is loading at startup and userlogon

Summary from: http://osxdaily.com/2010/02/17/track-down-all-startup-login-script-and-application-launches-in-mac-os-x/

Apps loaded at startup

  1. /Library/StartupItems
  2. /Library/LaunchDaemons
  3. /System/Library/LaunchDaemons

User (ran at user logon):

  1.  ~/Library/LaunchAgents
    • Found this guy: com.google.keystone.agent.plist
    • Google updater, decided to keep it, but if you want to read mode try this post
  2. /Library/LaunchAgents/
  3. /System/Library/LaunchAgents/

Crons:

  1. crontab -l

Kernell extensions

  1. kextstat | grep YOUR_QUERY

Login and LogOut Hooks:

  1. defaults read com.apple.loginwindow LoginHook
  2. defaults read com.apple.loginwindow LogoutHook