It’s time for the Git cheat sheet for writers!
General command structure:
command -o --option argument "another argument, containing blank spaces"
Note that Git commands always start with the prefix git whereas Unix commands do not carry a prefix.
| Unix command | Description |
|---|---|
pwd | Print working directory = tell me which folder I am in |
ls | List all items in this directory |
cd <directory-path> | Change directory by indicating where to go (path to directory) |
cd .. | Move up one level |
cd . | . = “this directory”, so cd . = stay where you are. (However, the one dot is useful in, e.g.: git add .) |
cd ~ | ~ = home directory, so cd ~ = go to home directory. |
cd ~/<some-directory> | Go to some-directory right below the home directory |
mkdir | Make directory (Note: Creating a new directory won’t move you to that new directory. You’ll have to use cd <directory> to go there.) |
mv <current-file-name.xyz> <new-file-name.xyz> | Move file = rename it, or (Git logic): delete old file and create new file (that is thus unstaged) |
rm <filename.xyz> | Remove file = delete it |
| [Tab] key | Fill in the rest of a name |
| [Up arrow] key | Select the previous command (move back in time) |
| [Backspace] key | Go backwards (in a line) |
| [Space] key | Go forward (in a line) or: scrolls down |
| [q] key | Quit the execution of a command |
| Git command | Description |
|---|---|
git --version | Shows installed Git version |
git clone <repository-path> | Right-click to paste the copied repository URL into Git Bash |
git status | Shows the status of the files/ the repo, e.g., unstaged files |
git add <filename.xyz> | Stages a particular file |
git add . | Stages all files in the current directory |
git commit -m "Your commit message" | Commits all staged files with the message provided |
git push [<repo> <branch>] | Uploads changes (all commits) to repository. Note that you have to be signed in to the repo server to be able to push changes. |
git push origin <your-branch> | Uploads the changes to your-branch of the default repo (=origin) |
git config --global user.email "<youremail@domain.xyz>" | Sets default identity for Git (1/2). Omit --global to set the identity only for the repository you are currently working on. |
git config --global user.name "<Your Name>" | Sets default identity for Git (2/2). |
git log | Shows the repo’s history |
git log --oneline | Shows a compact version of the history, including commit numbers |
git checkout <commit-number> | Sets the HEAD label to a certain commit (= all documents will be displayed according to their state at the time of that commit) |
git checkout master | Sets the HEAD label back to the most recent commit on the master branch |
git checkout <your-branch> | Sets the HEAD label back to the most recent commit on your-branch |
Read more about how this cheat sheet came to be:
How I learned Git, forgot it, and re-learned it
Part 1: Why you need to learn Git for Docs as Code Docs as Code. What? In the software industry, technical writers work close to developers, especially when writing developer documentation, that is, documents that have other developers as target users. The idea of Docs as Code is to employ the same workflows for the…