Sign in
Short Git Guide
Short Git Guide

Setup

Download Git for Linux
Download Git for Linux
Download Git for Windows

Create Git Repository

Create a new directory
Enter into directory
cd new_directory_path
Create a new repository
git init

Checkout a Repository

create a working copy of a local/remote repository by running the command
git clone /path/to/repository
when using a remote server, your command will be
git clone /path/to/repository

Git Workflow

Files in a repository go through three stages before being under version control with git:

  • Untracked: the file exists, but is not part of git's version control
  • Staged: the file has been added to Git's version control but changes have not been committed
  • Committed: the change has been committed

Git-status is used to understand what stage the files in a repository are at.
git status

Stage

Add our files to the staging area:
git add file.txt

Commit

The final stage is to commit the change we have made. We do this by recording a short message that explains what we did and why. This human-readable explanation will go alongside Git's own record of the change and the file structure snapshot at that point.
git commit
This pops open your default text editor (depending on what you configured in your setup stage) and asks for a commit message.
We can view the difference between that version of the file and the committed one (eg the changes) using the following command:
git diff

Ignoring files

There are many scenarios where you might end up with files in your repository that you don't want to place under source control. You can place these in a file called .gitignore (which will be hidden by default).

Removing and renaming files

Git uses the unix mv (move or rename) and rm (remove) commands, but also deals with the tasks of staging and unstaging the files too.

  • rm file # removes a file that hasn't been added to the repository yet- this will delete the file from your file system
  • git rm file # removes the file from the repository and deletes it from your file system
  • git rm --cached file # removes the file from the repository but doesn't delete it from your file system

Pushing Changes

Your changes are now in the HEAD of your local working copy. To send those changes to your remote repository, execute
git push origin master
Change master to whatever branch you want to push your changes to.

If you have not cloned an existing repository and want to connect your repository to a remote server, you need to add it with
git remote add origin server_url
Now you are able to push your changes to the selected remote server

    Was this page helpful?
    Newsletter Subscription
    Subscribing you to the mailing list