Git and github stuff

From Ed's Mediawiki
Revision as of 20:33, 21 May 2021 by Eburdick (talk | contribs) (Git and GitHub Stuff)

I use Git and GitHub to version manage all software I write and maintain. I started using it with IDEs, like PyCharm and Android Studio, with support for Git built in, so I didn't really have to learn what was under the hood. Now using it with the Arduino IDE, I need to know enough to more directly use it. In addition, GitHub deprecating username/password authentication kind of forced me to dig into it some.

Git Basics

First of all, I user Git on Windows, so I am running Git for Windows (64 bit.) This includes the base Git software, which is available from the command line, Git Bash, which is an alternative Unix command line, Git Command, which is just an alternative Windows CMD window, and Git GUI, which is a graphical interface for Git. After trying GitHub Desktop and Tortoise Git, which are pretty decent GUIs, but have problems with authentication, I have settled on stuff directly from Git, which is a little clunky, but seems to always work.

To create and work on a local Git repository, you need to set the working directly to the directory that contains the code. E.G. for my current Arduino code, this is in C:\development\arduino\ejbfleet-v1\ The Git directory, .git is in there along with the source files.

Git Functions I Use All The Time

Git clone

Clones a repository, either local or remote (generally on GitHub.) I use this to copy up to date code to a machine where I want to work on it. For me, I generally start a coding project on ejbdesk or ejblap, and eventually have occasion to work on it on the other machine, and possible on my shop machine, ejbshop.

Git add .

In the gui, this is Stage Changed. Not sure why they use a different name, add vs stage, but so be it. This sets up all changed files to be committed to the repository. Git add <filename> or Git add <directory name> will stage specific things to commit.

Git commit

This commits staged files to the repository, i.e. marks them as changed.

Git push

This sends the repository to a remote repository (GitHub for me.) What it is really doing is sending the changes, so we can keep track of them. If the GitHub repository is now cloned, the whole history will come with it.

Git pull

This updates a local repository with new data from a remote repository. I use this to keep my machines tracking. E.G. I make some changes and pushes from my laptop and I want to work on the stuff on the desktop. I use the pull command on the desktop to pull these changes into the local repository on that machine. It will also update the files based on changes made to the pulled repository.