First steps with Git

Learn just enough about git to move forward.

First Steps with Git

It's time to get your code under version control.

Version control tracks changes the changes to your files. This allows any developer working on or examining the code to have full access to the full codebase, and it's complete history.

This has many benefits.

  • Change history makes it easy to understand what changed when, and why, for any given file.
  • Using a third-party provider, such as github.com, provides a stable and reliable home for your code.
  • Development is made more portable. Your local copy of the code can easily be recreated on a new device at any time.
  • Makes it easier for developers to collaborate on a common codebase.
  • Enables simultaneous work-in-progress on several aspects of the project with minimal hassle.

Git has emerged as the most popular, and most used version control system.

Along with that, github is a leader in hosted git repository infrastructure. Github provides you a stable, secure, and reliable host for all your git repositories.


In this guide, you will:

  • Ensure you have a Github account
  • Configure Git on your Local Computer
  • Create a Repository for learning_laravel
  • Add your Code to the Repository
  • Review your Progress on Github

Ensure You Have a Github Account

Visit https://github.com.

If you already have an account, ensure you are logged in correctly.

If you don't have an account, click the Sign Up link in the upper right and step through the account creation process.

Before proceeding, ensure you have verified your email address with github.

If this is a new account, you should have received an email from github for this process.

If you do not see this email, or if this is not a new account, you should review github's documentation at https://docs.github.com/en/free-pro-team@latest/github/getting-started-with-github/verifying-your-email-address to help ensure your email address is validated.

Next, you should create a personal access token. This token will be used for authentication when you interact with github from the command line.

To ensure you create a personal access token correctly, you should follow the directions from github's documentation on the topic at https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token .

Once you have a token, I recommend storing it in a secure password manager, such as bitwarden or lastpass. You will need this token in a later step, and also may need to reauthenticate using it from time to time.


Configure Git on your Local Computer

There are a few system-wide settings for your local git working environment which will make working with it much easier. You should set those now.

The user.email and user.name configurations set the identifying values git will associate with code changes you make.

The credential.helper configuration sets git to remember your authentication credentials. With this set to cache, you will be prompted for a username and password only the first time you push changes.

git config --global user.email "{ your email address }"
git config --global user.name "{ your name }"

The final command varies based upon the operating system you are using.

For linux based systems, use:

git config --global credential.helper cache 

If you are on mac, instead use:

git config --global credential.helper osxkeychain

Finally, for windows, you should use use:

git config --global credential.helper manager

git config


Create a Repository for learning_laravel

Within Github, you will have a repository for each project you are working on.

Now is a good time to create an empty repository for the learning_laravel project these tutorials will be walking you through.

Visit https://github.com/new.

Enter learning_laravel as the repository name.

You are free to leave 'description' blank, or enter a short description if you like.

Select Private, and not Public.

Ensure the README, .gitignore, and license options are all unchecked.

Click 'create a repository'


Add your Code to the Repository

For this step, you can simply follow github's on-screen instructions for creating a new repository from the command line.

You can, however, skip the first line, echo "# learning_laravel" >> README.md. This line intends to ensure you have a file to commit. You already have the Laravel framework insallation to work with.

Note that the text inside the quotes in the git commit -m line is a short description of the changes you are submitting, and will be visible when viewing the history of the files going forward. This is your chance to provide an articulate and concise summary of what has changed.

git init
git add .
git commit -m "install Laravel framework"
git branch -M main
git remote add origin { repository url }
git push -u origin main

You will be prompted for your username and password at this point.

You should enter the username you used for creating your github account.

For the password, you should use the personal access token you created within your github account.

git push


Review your Progress on Github

Finally, you are ready to reload the github page showing your learning_laravel repository. You should now see a copy of your local laravel installation, successfully pushed to github.

git brownser view


Finished!

Next up, it's time for a crash-course in Resourceful Routing Theory!