EBAVS/ Try to work hard with 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 in 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):
$ mkdir /var/www/example
$ cd /var/www/example
Then we initialise git repository. This is important because git makes their local repository for local working:
$ git init
Initialized empty Git repository in /var/www/example/.git/
Working with Repository
When you initialized we can begin work, then create a simple file for testing:
$ nano index.php
then add simple code:
now add this file to a repository:
$ git add .
$ git add index.php
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:
$ git commit -m "initial code submit"
[master (root-commit) 6f30a7f] initial commit
1 file changed, 1 insertion(+)
create mode 100644 index.php
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 next commit:
$ nano index.php
And change to:
echo "php file modified";
$ git commit -a -m "modifications"
[master 67e5f24] modifications
1 file changed, 3 insertions(+), 1 deletion(-)
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:
A user is your username and Repo are the repository name. For this example a real URL could be:
Then is time to add this remote repository to our local repository:
$ git remote add origin https://github.com/ebavs/example.git
We have connected now our local repo with our remote repo, time to move code to remote:
$ git push -u origin master
Username for 'https://github.com': ebavs
Password for 'https://email@example.com':
Counting objects: 6, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (6/6), 452 bytes | 0 bytes/s, done.
Total 6 (delta 0), reused 0 (delta 0)
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
And we have our repo working.
commands that we used:
# initialize repository
# add all files in repository
git add .
# submit code, make commit
git commit -m "initial code submit"
#submit code, make commit
git commit -a -m "initial code submit"
# Add remote repository
git remote add origin https://github.com/ebavs/example.git
# submit code to remote repository
git push -u origin master
If you like it you can visit our next post talking about Git: