Basic Git Commands

,
git logo

EBAVS/ Try to work hard with the latest technologies. We work with git for several years and we learned a lot.

This is a simple reference guide with commands that we use day to day from the beginning of a project.

 

Initialising Repo with Git

First of all, we create a project (actually we download skeletons from a composer, but this is another history or post):

Then we initialise the git repository. This is important because git makes their local repository for local working:

Working with Repository

When you initialized we can begin work, then create a sample file for testing:

then add simple code:

now add this file to a repository:

or

Now we have a repository with some of the code. It’s time to move this code, we have code added but isn’t in the repo yet. Write:

The files are committed to a repo, are stored in this and assigned a short guide identifier 6f30a7f for us.

Go to change index.php and see what happens in the next commit:

And change to:

Look what we add -a parameter. This means that we change a file. If we only add files don’t need -a parameter.

We have our application ready to store on the remote server. We could make a remote in GitHub or in Bitbucket. I Have a preference for bitbucket because I can make private repos for free. But GitHub is good too.

When we make a repository, in GitHub for example, they make a new URL for the repository, the URL construction is:

https://github.com/user/repo.git

A user is your username and Repo are the repository name.  For this example a real URL could be:

Example Git EBAVS/

Then is time to add this remote repository to our local repository:

We have connected now our local repo with our remote repo, time to move code to remote:

And we have our repo working.

Summary

commands that we used:

 

Update:

If you like it you can visit our next post talking about Git: