Skip to main content

Git My Way

Update: This blog was written about two years before Github dropping the so-called divisive "master" terminology, and renamed it to "main". But I'm not going to change anything here. I just want to keep the original context as is. Please read master as main. After all this while I still could not remember how to do git right, and I kept on coming back to this blog, each and every time I wanted to update a Github repo. If you are careless then you may encounter "fatal: Couldn't find remote ref master", and Google will lead you into a pit of old and unrelated discussions.

I used to bookmark a number of git tutorials. Most of it works but only to a certain extend until I forgot most of the required steps later. The steps were not intuitive and can easily be forgotten. Git uses alien English. Then I realize that I have to list my own way of using git. I believe all of you have too because we depend on it.

I use git with Github and mostly to update the master. What the heck is the master? A copy in my laptop or a copy in Github? Git has a plethora of confusing terms. I believe the designers chose to confuse themselves so that others will too. It is important that only a small number of users know how to use git so that they remain to be the masters of git.

I write this post when I am in a middle of a git process. I forgot how I started it. I was focusing on writing my codes.

Step 1 - Create a Github Repository

It is a repository of a master code. Why must the master be in the repository? Should a repository only hold a copy of the master? Anyway, a master is not really a master. It can be copied into many repositories. Anyway, the one on Github is the master. The one on my computer is a local copy.

So, the one on my laptop is not really the master even though most major features started there. Even if I start coding on my laptop prior to creating the Github repo I have to consider the copy I started with is not the master. The one I have is called the local working copy. Why is it make sense?

If I started coding directly on Github or initially uploaded my original code into a repository then I need to clone it into my computer:
$ git clone https://github.com/MY-USERNAME/MY-REPOSITORY
A repository folder containing the cloned code will be created on my computer.

Use  git status

At least with git status I have some idea regarding the copy in my laptop. Most tutorials ignore this.

Step 2 - Always Pull from the Github Master into My Laptop

Before touching anything on my local copy I have to pull the master first:
$ git pull origin master
Somehow the Gihub master may have changed while I am coding on my laptop. Maybe I updated the README.md file. So, I must make sure I have the latest master.

Note: At this moment I forgot how I created the copy in my laptop. Did I clone Github? Or did I run git init with git remote add origin <server>? I will get back to this when I create a new project. See, how forgettable it can be.

Okay. I first created a project on my notebook. I worked on it until it gained a reasonable shape that I thought it will be viable. Then, I created a Github repo for the project. In my local project folder, I ran git init followed with git remote add origin <server>. Then I ran git pull origin master before I added the project files into the repo for initial commit.

Step 3 - Add File

$ git add <filename>
Add my code file into git INDEX each time before commit. But the file doesn't get anywhere useful yet. I need few other steps. I don't want to comment on INDEX or stage.

I can use wild-cut for all edited files:
$ git add *

Step 4 - Commit

$ git commit -m "Commit message"
It commited to the HEAD in my laptop. But not to the master in Github yet. I don't need to know what HEAD is, the branches and the trees. And I don't care as long as it works. Maybe I need to know it when my code becomes big and complex. Why must I make my code to become big and complex? Is git promoting big and complex coding?

Step 5 - Push Back to the Github Master

$ git push origin master
Now my code becomes the master in Github. And I can go back to coding.

Update: You may need to move the master branch to 'main' before pushing it back to Github.
$ git branch -m master main

Comments

Popular posts from this blog

Setting Up PyScripter for Quantum GIS

PyScripter is a general purpose Python Integrated Development Environment (IDE). Quantum GIS (QGIS) is a desktop GIS application that can be extended with Python plugins. Both are open source softwares. We intend to use PyScripter as an IDE to build QGIS Python plugin. We are using PyScripter 2.4.1.0 and QGIS 1.6.0 in Windows. PyScripter does not come with Python. On the other hand, QGIS is built in with Python. Thus, we will setup up PyScripter to use the build in Python in QGIS. We assume both PyScripter and QGIS are already installed. Preparing PyScripter batch file We assume that QGIS is installed in C:\OSGeo4W\ folder and PyScripter is installed in C:\Program Files\PyScripter\ . 1. Copy qgis.bat in C:\OSGeo4W\ bin to pyscripter.bat 2. Edit pyscripter.bat to remove the last line that read something like this start "Quantum GIS" /B "%OSGEO4W_ROOT%"\apps\qgis\bin\qgis.exe %* and replace it with this in one line Start "PyScripter" /B "C:\Progr...

Using React in Foundation for Sites

This post was the precursor to the Foundation-React Template . React and Foundation are two different web UI frameworks addressing different needs. They evolve differently. Both of them are powerful on their own accord. Fusing them together may create superpower. We will walk through the process of adding React into Foundation. We will start by installing both Foundation and React through command line interface (CLI). Then we will create a simple Todo web app. Along the way we will highlight the development process. But before all that, let us summarize React and Foundation. The details can be found at their respective websites. Both of them are well documented. React is a run-time UI rendering engine. It renders dynamic UI elements in its own fast virtual DOM, and only update necessary changes to the slow browser DOM. This behaves like a  double buffering DOM which makes any UI update feels fast. React wraps a UI rendering script in a component. A React component can ...

Debugging PHP using Apache Error Log

PHP runs on the server side and behaves like a function that return a value against the given arguments. A remote client may call this function and expect a specified return value and nothing else. So how do we debug this function ? It must not return debugging messages since the client is never designed to handle them. We must never burden any client to handle debugging messages. If we run PHP through Apache server then we can use the error log to keep our debugging messages. It may not be the best way to do it. But we only want to talk about this approach now. Error Logs The Apache error log files generally can be found in the following directory: var/log/apache2 We issue the following command from within the directory to read the latest error messages: # tail error.log The tail command reads the last few lines from the error.log file and prints them on the terminal. If we need to read a specific number of lines from the end of the file then we can specify the -n opti...