Git and GitHub

The best reference I keep going back to is this one Learn Git - Tutorials, Workflows and Commands | Atlassian.

The key concept that, once I got it, made things easier was understanding what upstream, origin and local were. This answer helps git - What is the difference between origin and upstream on GitHub? - Stack Overflow - note the directions of flow of changes between the repositories.

  • upstream - for instance emoncms/emoncms
  • origin - the ‘origin’ of your local repository. You will ‘fork’ into an origin (e.g. borpin/emoncms). This is usually a remote repository (GitHub or an alternative).
  • local - the local copy on your machine.

The usual flow of changes is:

  • I pull changes from upstream to local (keeps local in sync with upstream)
  • I push those changes from local to origin (keeps my fork origin in sync with the upstream)
  • Any changes I make, are made in local (preferably to a new branch I create), I then commit these changes to local and push that commit to origin.

Each one of these repositories can have different branches - usually a copy of the ‘master’ branch.

What I have found, when making changes, is to make sure my local master branch is level with the upstream master, then create a new branch in which I make my edits.

The final concept is the Pull Request - me asking the maintainers of the upstream repository, if they could pull my changes, from origin/my branch into the upstream master branch.

I have not yet done anything that involves me directly collaborating with anyone else at the same time on the same code, so I have yet to discover how that works :smile:.

You mentioned about how you know what version you have ‘pulled’. The answer there is to create a tag, but that is another conversation, although by looking at the last commit (or the HEAD) will tell you the last change made.

I really struggled with understanding these concepts of git at first but I stuck with it as I wanted to be able to contribute to various projects. I also started using GitHub Desktop which made a world of difference to me (no Linux port it seems) and there seems to be quite a bit of effort going into developing this product. VSCode is also integrating git more and more I see.