These are the most common git
commands I use while working on a project.
git init
git clone
git status
git remote
git add
git commit
git push
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
where to send the files when you use the git push
commandgit add <FILENAME>
git add <FILENAME>
What it does:
Useful when:
git add .
What it does:
Useful when:
git add
you need to list individual file names after the command so this is useful when you’ve made lots changes.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:
"fix broken link"
)Useful when:
git commit -am "<COMMIT MSG GOES HERE>"
What it does:
-am
tag is for adding the untracked files to staging (the a
part) and attaching the message (m
) for the commitUseful when:
add
and commit
(i.e., git push
git push
What it does:
Useful when:
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.
git branch <NAME>
: Creates a new branch with desired name (e.g., "add-feature"
)git checkout <NAME>
: Moves to specified branch (e.g., from main
to add-feature
)git checkout -b <NAME>
: Creates new branch and moves to that branchgit branch -d <NAME>
: Deletes specified branchgit fetch
: Fetches new changes from remote repogit merge <NAME>
: Merges changes from the named branch into the current branchThis 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.
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: