Git guide for beginners

Incomplete |

Install git

Install git from the official website: https://git-scm.com

Authenticating git

We need to set up our Github username and password. Once git is installed, set it up using these commands on Terminal:

git config --global user.name <Github username>
git config --global user.email <Github email>

When prompted, type in your password and hit enter.

To check which user credentials are currently logged in:

git config user.name
git config user.email 

Basic command line

  • Creating a directory: mkdir <folder_name>
  • Creating a file: touch <filename.txt>
  • Deleting a file: rm <filename.txt>
  • Deleting an empty directory: rmdir <folder_name>
  • Delete a directory with all files inside it: rm -rf <folder_name>

Initialise git

Change directory into your project folder and initialise git as follows:

git init

Quick diagram of how git works

Staging

To see which files are in the staging area:

git status

To add a specific file to the staging area:

git add <filename.txt>

Adding files

To add files to the staging area, there are a few different commands depending on what you want to do.

To stage all changes (including new files, modifications and deletions):

git add -A

To stage only new files and modifications (not deletions):

git add .

To stage only modifications and deletions (not new files):

git add -u

By the way:

  • git add -A is the same as git add --all
  • git add -u is the same as git add --update

The . means the current directory:

Commit

To commit the files in your staging area:

git commit

Source and more info

  1. https://dev.to/tracycss/git-and-github-for-beginners-po3 (incomplete)
  2. https://stackoverflow.com/questions/572549/difference-between-git-add-a-and-git-add
Show Comments