LearnInPublic

Git Cheatsheet

These are the most common git commands I use while working on a project.

Contents

git init

git init

What it does:

Useful when:

git clone <URL>

git clone <URL>

What it does:

Useful when:

git status

git status

What it does:

Useful when:

git remote add origin <URL>

git remote add origin <URL>

What it does:

Useful when:

git add <FILENAME>

git add <FILENAME>

What it does:

Useful when:

Variant

git add .

What it does:

Useful when:

CAUTION: Including all files may also include hidden files (e.g., .DS_Store) within the directory where your repo is located. These kinds of files often contain system metadata, however you may not want them in your repo repository, especially if it’s a public one.

Further, you may be working on a project that contains access keys. If you add these files and commit them, then push them to a public repo they become available to the public. This could be bad news if these keys give access to a private database.

To solve this, you can either move these files to another directory or add them to a .gitignore file. This file contains a list of files and directories that git will ignore (i.e., it won’t track any changes, stage them for commits, or push them to remote repos).

git commit -m "<COMMIT MSG GOES HERE>"

git commit -m "<COMMIT MSG GOES HERE>"

What it does:

Useful when:

Variant

git commit -am "<COMMIT MSG GOES HERE>"

What it does:

Useful when:

git push

git push

What it does:

Useful when:

Variant

git push --all --set-upstream origin

What it does:

Useful when:

Note: Unless you decide to change the upstream, you only need to this once. I usually do it on my first push.

Other commands

Resources

References

License

This code is made available via the GNU GPLv3 license.

You are free to use, copy, modify, and distribute this software under the terms of the GNU GPLv3 license. This means:

For more details, please refer to the full text of the GNU GPLv3 license for this project.

Author

Thank you for reading about this project. If you’d like to connect with me for mentoring, collaboration, or employment opportunities, you can do so via the following links: