Git is a version control system used for tracking changes to files.
To utilize the git version control system, one must first initialize a repository; a repository can be initialize by the command git init
in your git console. To ensure a file is being tracked by git, one must add files to the repository by the command git add <FILENAME HERE>
, this will stage the file in the current working branch.
Branches are used to develop changes to the files isolated from each other. The master
branch is the "default" branch when you create a repository. Use other branches for development and merge them back to the master branch upon completion. To create a new branch utilize the command git checkout -b <BRANCH NAME HERE>
, and to switch back to the master branch, utilize the command git checkout master
.
Git can tell when a file is modified and show the changes via the command git status
once the file has been staged. To store a change to the repository, one must commit the changes. This can be done via the command git commit -m "<MESSAGE ABOUT CHANGES HERE>"
.
Git can be used to coordinate work on those files by using a remote repository by utilizing a site such as http://GitHub.com. To make your local git repository remote, you must add the remote origin by utilizing the command git remote add origin <URL TO REMOTE REPOSITORY>
in your git console. Be weary when working with a remote repository, a branch is not available to others unless you push the branch to your remote repository by utilizing the command git push origin <BRANCH NAME HERE>
.
Sometimes multiple people may try to edit the same content. If one tries to edit code that someone else is editing, a merge conflict may occur. To alleviate the occurrence of conflicts work should be done in separate isolated branches. The most direct way to resolve a merge conflict is to edit the conflicted file. Open the merge.txt file in a text editor, and review the conflicts, and erase the changes that are not needed; keep the ones that are.