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

Sending Emails via SMTP

msmtp  requires a minimal setup for sending emails via SMTP compared to sendmail. Here is a configuration for you to send emails from a web host to an external SMTP server. Prior to doing that, you must check whether there is a clear communication channel between your web host and the SMTP server. You can use Telnet . Set up msmtp You are going to set msmtp as an MTA . Hence, you need to remove all other MTAs such as postfix and sendmail: $ sudo apt-get --purge autoremove postfix sendmail Install msmtp and related utilities: $ sudo apt-get install msmtp msmtp-mta mailutils Configure msmtp: $ sudo nano /etc/msmtprc # Set default values for all following accounts. defaults # Use the mail submission port 587 instead of the SMTP port 25. port 587 # Always use TLS. tls on # Set a list of trusted CAs for TLS. The default is to use system settings, but # you can select your own file. tls_trust_file /etc/ssl/certs/ca-certificates.crt # The SMTP server account mx host mail.mx.example

fatal: Couldn't find remote ref master

If you are using Github then  master is now known as main . Whatever you want to do with a master must now be referred to a main . If you search for this error message on the Internet then you will encounter with a lot of old discussions on how to set up your master properly which is probably not what you are looking for. The master  is your problem. Rename it to main . I wrote Git My Way about two years ago. Today I created another Github repository. I got this  "fatal: Couldn't find remote ref master"  error message when I wanted to sync the new repo for the first time with my notebook using the notes I wrote in the blog. All the discussions around the error message I found on the Internet were perplexing. Then I recalled that Github had renamed master to main  due to the master-slave connotation. We always have a master copy of a code, never a slave copy. Now suddenly a word context has been diminished for good. What is going to happen to the existing vast documen