Git Workflow Cheat Sheet By: Monique Danao, Corey Leung December 18, 2017 Updated November 22, 2023 Estimated reading time: 2 minutes. Git is a distributed version control system that lets developers track changes in their codebase, collaborate with others, and manage different versions of their projects. Created by Linus Torvalds in 2005, Git has become the industry standard for version control due to its speed, flexibility, and powerful branching function. The Git ecosystem is vast, and navigating its complex commands and workflows can be intimidating for newcomers. Still, a git workflow process is seen by many as essential for any project, so we've developed a cheat sheet to help you get started. What is Git? Git allows developers to easily track project versions, see changes between old and new code files, segment projects into branches and more. Git allows developers to create a repository (or repo) that stores their project's entire history and all changes made to their files over time. The project history is recorded through commits, which show specific snapshots of the code at different points. Developers can create branches to work on features or fixes independently. Once they’re done, they can merge their changes back into the main branch, otherwise known as "master" or "main." Start your git repository On your local machine: mkdir myproject: Creates a new directory to put all the files into for your project. Replace ‘myproject’ with a simple but descriptive name for your project. cd myproject: Change directory to your new project. git init: Initialize your new directory to be a git repository. touch README.md: Create an empty file in your directory named README.md. It is recommended to write up the description of your project here. git add README.md: Add this file into your git repository. Git will begin tracking changes to this file. git commit -m “Initial commit”: Commit the changes you have made to your repository in to git’s system, and add the comment that it is your initial commit. ALL commits require a message/comment. Github Actions Log into GitHub Click ‘New Repository’ On the next page, give your repository a unique name Leave it public and click on 'Create Repository' at the bottom On the next page, find the section for existing repositories and copy the two commands they give you to your clipboard In your Terminal, run the two commands from GitHub Connect Local to Remote On your local machine: git remote add origin <paste SSH Clone URL>: Register with your local git repository that you will be distributing all changes to a remote repository. git remote -v: Verify that your local git repository can speak/sync with the remote one. git push -u origin master: Push all changes to your master branch up to your remote repository. The-u flag means that git will use this remote/local combination when you type ‘git push’ going forward (until you specify a new combination). Make a Branch On your local machine: git checkout -b mynewbranch: This creates a new branch and switches to it in one command. Merging Branches On your local machine: git checkout master: Switch back to master branch git merge mynewbranch: Merge all of the differences between branch and master into the master branch. This brings all the work you have done in your branch in to the master branch git push origin master: Push all the changes you have made to your code by merging your branch to the remote repository.