This article is an introduction to using the Git version control system on A2 Hosting servers.
The popular Git version control system is installed on all A2 Hosting shared and reseller accounts. For VPS and Dedicated Server accounts, you can install Git manually yourself, or we can install it for you upon request. Like other version control systems, Git enables you to track multiple revisions of files and directories.
The following sections are a brief introduction to Git's basic features.
To create a Git repository, all you have to do is log in to your A2 Hosting account using SSH, and then type the following command:
git init repository
Replace repository with the name of the directory where you want to create the repository (if the directory does not already exist, the git init command creates it).
Change the current working directory to the new repository:
To take a snapshot of all of the files currently in the repository directory, type the following command:
git add .
The git add command puts the files in a temporary staging area that Git calls the “index”. To commit the files to the repository permanently, type the following command:
A text editor opens, and you can type a commit message that describes the changes. Save the message, and then Git adds the changes to the repository.
You may receive the following message when you try to commit changes:
Please tell me who you are.
If you receive this message, type the following commands, using your own e-mail address and name:
git config --global user.email "[email protected]" git config --global user.name "Your Name"
Git makes it easy to update a repository. After you edit a file or files, you update Git's file “snapshot” by using the git add command. To make the changes to the repository permanent, use the git commit command.
You can combine the git add and git commit commands by typing the following command instead:
git commit -a
You can even include the commit message on the command line by using the -m option. Replace message with your commit message:
git commit -a -m "message"
To view changes you have made to files in the repository since the last commit, type the following command:
Similarly, to view a list of changes that have already been committed to the repository, type the following command:
A single Git repository can maintain multiple development branches. For example, you could create a “testing” branch and a “production” branch to track changes for different versions.
To create a new branch, type the following command, replacing name with the name of the new branch:
git branch name
To see a list of all branches in a repository, type the following command:
The asterisk (*) next to a branch name indicates the current working branch. If you want to work on another branch, type the following command, replacing name with the name of the branch:
git checkout name
You can then make changes in the branch and commit them with the git commit command. If you switch to another branch, you will not see those changes in the branch.
To merge changes from one branch into another branch, type the following command. Replace name with the name of branch that has the changes you want to merge:
git merge name
The changes in source branch name are then merged into the destination branch (the current working directory).
You can “clone” repositories. When you clone a repository, git makes an exact copy of an existing repository. For example, say you have a repository named project. To clone the repository into a directory named projectclone, you would type the following command, replacing username with your own account username:
git clone /home/username/project /home/username/projectclone
Now there is an exact copy of the project repository in the projectclone directory.
Suppose you (or another developer) make changes in the projectclone directory that you want to pull back into the original project directory. To do this, you would type the following commands, again replacing username with your own account username:
cd /home/username/project git pull /home/username/projectclone master
The git pull command fulfills two functions. First, it fetches changes from a remote repository (in this case, the projectclone repository). Second, it merges those changes into the current working repository (in this case, the project repository).
If you try to clone a Git repository stored on a remote server (such as GitHub) by using HTTPS, you may receive the following error message:
error: error setting certificate verify locations: CAfile: /etc/pki/tls/certs/ca-bundle.crt CApath: none while accessing https://example.com/repository/ fatal: HTTP request failed
This error occurs when your account has the jailshell enabled. Please open a ticket on the Customer Portal at https://my.a2hosting.com and request normal shell access for your account.
To view the official Git documentation, including reference guides, tutorials, cheat sheets, and more, please visit http://git-scm.com/documentation.
Subscribe to receive weekly cutting edge tips, strategies, and news you need to grow your web business.
No charge. Unsubscribe anytime.
Usamos cookies con el fin de personalizar para usted nuestro sitio Web y analizar el uso de éste. Usted acepta esto haciendo clic en “Acepto” o al continuar usando el sitio Web. Hay más información sobre cookies en nuestra política de privacidad.