My Git essentials

|

This post is work-in-progress!

These are my essential commands for Git because I always forget them:

Initialize a Git repository

Initialize an empty Git repository in a directory called directory-name under the current directory.

git init directory-name

Initialize an empty Git repository in the current directory.

git init

Initialize an empty and bare Git repository in the current directory. Bare means this repository will contain only Git data but no working tree.

git init --bare

Add files/directories from your worktree to your repository

Add all files (and files in directories) in and under your current directory to your repository.

git add .

Add a specific (new) file to the repository.

git add mynewfile.php

or

git add some/subdir/mynewfile.php

Check the state of your worktree

The status command returns a list of files that are changed, renamed, deleted or newly added to the worktree.

git status

Add changed files to the next commit

After changing one or several files you want to lay down the edits in an event called commit. Though you've edited several files you may only want to include some of them in your next commit.

git add file1.php
git add file2.php
git add subdir/another_file.php

After you've added all necessary files you can commit them:

git commit -m "My commit message"

This command commits all added files. To identify your commit a commit message with the conent "My commit message" is added to the commit.

If you want to include all changed files in your commit just use the -a switch:

git commit -a -m "Commit all changed files"
blog comments powered by Disqus