Skip to content

Instantly share code, notes, and snippets.

@N-Gibson
Last active April 15, 2019 04:51
Show Gist options
  • Save N-Gibson/27c539aa0f678d5a19f3cd0957b8871c to your computer and use it in GitHub Desktop.
Save N-Gibson/27c539aa0f678d5a19f3cd0957b8871c to your computer and use it in GitHub Desktop.

Beginners Guide to Git

There are a few things that are important to know while getting introduced to Git.

  1. Git is a way to track changes in a project. It can be done by an individual or a group of individuals.
  2. It essentially takes a snapshot of a project, the time it was changed and you can add a handy title as well. From there it allows all of those snapshots to be accessed for editing or time travel (in your code)!
  3. These allow for a much easier and more effective experience making new, and editing code that is preexisting.

How to use Git

There are quite a few steps to use Git, but once you get a hang of them it's not so scary.

    • Step one is to make a directory and a file inside that directory. This can be done in terminal using the mkdir command followed by touch .
    • From here, you have to run git init to initialize the program and start the trackment process.
    • Once git has begun, a project can be added to the staging area where any small changes can be addressed. The command used to move a file from untracked to the staging area is git add followed by the file name (ex. git_practice.txt).
    • At this point, you're ready for the projects first commit. Using git commit -m (including a brief denotation of the changes made). This is the first snapshot!
    • After this point changes can be repeatedly made, staged and committed. When you're ready to push these changes to GitHub, the git push command will add those changes to the repository there.

Samples

sample_admin~$ mkdir git_beginner
sample_admin~$ cd git_beginner
sample_admin~/git_beginner$ touch experimenting_git.txt
sample_admin~/git_beginner$ git init
Initialized empty Git repository in /Users/sample_admin/git_beginner/.git/
sample_admin~/git_beginner$ sublime .

*added some text to experimenting_git.txt*

sample_admin~/git_beginner$ git add experimenting_git.txt
sample_admin~/git_beginner$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

	new file:   experimenting_git.txt

sample_admin~/git_beginner$ git push
fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using

    git remote add <name> <url>

and then push using the remote name

    git push <name>

This last section requires a place to push the file to. Due to the fact this is a sample and there is no repo on GitHub, I recieved this message.

handy git tip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment