dev209

github page for dev209.com

View on GitHub

Git is a tool to control versions of code that each live independently on every system, this is in contrast to a centralized version system where each version is dependent on a main servers version of the code. Where a Centralized versioning system would update the main code on the server every time there is an edit, with git you can keep parts of your code that are only edited on your own machine, and send code to an agreed upon place without locking other versions out from editing. Typically Git is commanded from the command prompt, or power shell in Windows, and bash, or zsh in linux or Mac OS. Any commands listed here should be agnostic of whichever platform you use, though anything in “[ ]” brackets is a place holder, you would not have brackets there in a real command.

If you view the code that you want to track with git as a shared folder, a repository is like a folder that holds each version of the code as a different folder. a new repository is started with the command git init

a Remote in git is the chosen repository that will be updated with any changes that you make on your own machine, when you choose to send those changes. To add a remote use the command git remote add [name to call remote] [ssh or https address of remote]

Branches are what git calls the different versions of code or likening back to folders, different folders inside of the repository. If you want to make some changes to the code and save them without breaking the working version of code, you would make a new branch, and when you work on this branch, you have to tell git that you are want it to update the branched version by checking it out. If you dont tell git you are working on a seperate branch it assumes you are editing the main version of code. the command to make a new branch named “beta” would be git branch beta.

when you want to take your edits in a branch and have them take effect in another branch, in git you preform a merge. this will try to replay the edits to the code or other files in a branch into the branch you have checked out though it doesnt directly use the version of the branch you are in, it uses a common ancestor of both to replay the edits until it finds something it cant justify, or it has reached the state of the changed branch. To merge the beta branch to the Master branch the command would be git merge beta if run while the master branch was currently checked out.

merge conflicts are what git has when the merge 3 way comparison using a common ancestor where a branch left the source branch finds something it can not justify. This generally happens when both the source branch and the branch you are trying to merge with it have been changed. it will stop the merge and allow you to edit the conflicting files to the state you wish them to be in, and both versions will be in the file with special characters to denote which version they are from.

An easy way to avoid this affecting the main branch of a repository is to keep the divergent branch up to date with the source branch where possible, so that if there is a conflict, it is in your divergent branch.