General Git Workflow
Scope
This document describes the generalized workflow most developers will use when first starting out with Git. Some of the concepts below are covered in more depth in other knowledge base articles.
Git-based Workflow
After first initializing a new Git repository or starting work on an existing one:
- You can start make modifications on the repository: adding, deleting, or editing files freely.
- Once you're done, you will need to stage your changes by
add
-ing them to Git. This will tell Git to track the specific files going forward. - Now it's time to
commit
these changes to your local copy of the repository. This allows Git to take a snapshot of your repository at the time of commit - After you've made one or more commits, the final step is to
push
these changes to the remote repository (which is usually hosted on Github). Pushing allows other developers to see your set of changes and in more advanced use cases, review and approve them.
Basic Commands
Here is a breakdown of some basic commands every person needs to know starting out with Git.
Initialize a new Git repository in the folder you run this command in.
git init
Add the specified file for Git to track and stage the changes of.
git add <file>
Show you the differences between the current staged changes and the previous commit.
git status
Save the changes to your local repository. The message should be something descriptive of the changes.
git commit -m <message>
Push all the commits you've made locally to the remote repository.
git push
Grab all the commits made remotely and merge them into your repository.
git pull
Create a copy of an existing Git repository locally.
git clone <url>
Switch to a different branch in the repository
git checkout
Create a new branch in the repository
git branch <name>
Additional Resources: Git Cheat Sheets
Remembering some of the basic/advanced Git commands can often be a hassle. Here are a couple of cheat sheets to help you along the way:
GitHub Cheat Sheet
Roger Dudler Cheat Sheet
Atlassian Cheat Sheet