Вы находитесь на странице: 1из 10

Git and GitHub - a simple explanation

GitHub is not the easiest website to use, and Git is certainly not the easiest version control system, but there are a few reasons why it has quickly become the industry standard, quickly overtaking previous version control systems such as SVN. Please note the differences between Git and GitHub: Git is the actual underlying protocol that allows you to add, commit and push changes. It is what the website GitHub is built upon. GitHub is nothing more than a front-end for that protocol, a place for you to upload your code. It is a Git version-controlled paste-bin. Okay so whats in it for me? One of the bases of GitHub is that is allows you to create Student accounts, which in turn let you create private projects, which you can share with whomever you want. This lets you create individual projects for each of your team projects, which you can then delete later on. You would want to delete them simply because the maximum number of private projects a Student account lets you create is 5. Also, having your code in GitHub means that you can no longer forget bringing your code with you (so as long as you have an internet connection); your code is everywhere and everyone in the team can contribute to the project without affecting changes to other peoples files. If someone deletes all files from the Git repository, then you can just go back to a previous version where the files are present. Thats the beauty of version control! How do I use it? Using Git and GitHub isnt the easiest thing in the world, but it also isnt the most complicated one. Im sure youve done more complicated things before. First of all youd want to create an account in GitHub, and then create a repository with that account. You may want your account to be a Student account, and you can make sure to create a Student account by creating a free personal account and then following this link (https:// github.com/edu) and using your student e-mail address (your university e-mail address).

The create repository site will look more or less like this:

Once you have that repository, you are ready to start adding files to it! Make note of your repository .git URL so that you can use it when uploading. It will look something like this: https://github.com/jslvtr/ temp_git.git.

Using command-line git For the sake of simplicity, there are only 5 commands that I will explain in this guide. These commands are git clone, git add, git commit, git push and git pull. There are many others but I will let you learn about them yourselves. Think of a git repository as 3 layers. There is the filesystem layer, where the files physically are in your computer. Then there is the commit layer, where you put files to add to the cloud storage. Finally there is the actual cloud, where the repository is stored online. When you add files, they get added to the filesystem layer. When you commit the repository, all of those files go to the commit layer. Finally you can push them onto the cloud. However, first of all you must clone your repository into your disk. This is so that git knows this is where your repository is, and so that you can actually use it locally and then update it in the cloud! Its as simple as doing git clone [git_address]. After the first clone, every time you want to update your local copy of a repository you will git pull it. Lets get a real-world example going!

First of all we must run git clone [git_address] [destination_path]. Since this is a public repository we wont need to supply any authentication details. I used . as destination path so that it would be cloned into the current folder instead of creating a new folder with the same name as the repository name, which is the default. Since our repository is very small it didnt take very long to clone. Then by running ls -al we see that the .git and README.md files are in our file system! Now wasnt that easy!

Now we can create a new file called hello.txt and add it to our repository. Lets see how that would be done.

We see that to create an empty file with the terminal we use the touch [filename] command. Then we run git add [filename] command to add it to the current .git repository. Since there can only be one repository in a folder, we know its the temp_git.git repository the one we are adding the files to. We can run git status -s to see that we have Added hello.txt.

And then we can commit the changes to the staging or commit area. But first of all, we must specify our username and e-mail address so that git knows what these are. This is because they both are recorded on every commit we make. $ git config --global user.name Your Username $ git config --global user.email you@somedomain.com

And then we can finally commit! The way to do this is git commit [-m your message]. If you skip the -m your message section then you will be prompted to enter a commit message with the command-line text editor of your choice, or the default if you have none selected.

And finally we get to push our changes to the cloud repository. We do this by running git push [git_address].

And now we may go to our GitHub address and see the changes in the cloud!

And so this is (very simply) how to use git through the command line! There is a lot more regarding branches, aliases, stashes, pulling and forking and lots more but they didnt fit in the very basic guide I wanted to write. Feel free to read other websites for more information. Here are a few links: http://gitref.org/basic/ https://www.kernel.org/pub/software/scm/git/docs/ http://git-scm.com/documentation http://www.git-scm.com/book http://www.codeschool.com/courses/git-real Have fun and I hope git will be useful for you!

Using the GitHub GUI The GitHub GUI can be nearly as confusing as the command-line interface in first instance. However, it then becomes useful. Whereas with the GUI you can see differences between the previous commit and the current commit more easily, and you get to push buttons, the CUI (character user interface) is slightly faster - unless you type really slowly! Each one to his own! You may prefer using the GUI or the CUI and it doesnt really matter. Let me explain to you how the GUI works... First of all, you will want to clone the repository to your computer. This will prompt you to select a path to clone the repository into. Remember a new folder will be created where the repository will be, and this folders name will be what you specify in the pop-up dialog.

After you have selected the destination, you should see the files in your file system! The next image is the commit history of your repository, including past commits!

Then I created a new file in the repository directory in my file system. This got picked up by the application, and it is shown as an Added file in the next image.

Here you can type your commit message and the extended description. You can check/uncheck files depending on which ones you want to commit.

Then click Commit & Sync (or just Commit if you dont want to sync this commit yet) to push the changes to the cloud repository! You would see something like this after a couple seconds:

Final notes I hope that Git and GitHub will be beneficial to you and your projects. Remember that private projects require username/password to make changes and make clone requests. Dont make a repository public if you need it to be private. It can be dangerous! If you have any further questions or would like to know more, there are plenty of more extended guides that will teach you everything you need to know about Git and GitHub. All the best, Jose Salvatierra

Вам также может понравиться