Github com in Russian step by step instructions. git

Resistance to change is a fundamental human trait. If there was no Git at the time you started with version control systems, it's highly likely that you started with Subversion. Often people say that Git is too complicated for beginners. However, I beg to differ with you.

In this article, I'll show you how you can use Git for your projects. Let's assume you're building a project from scratch and want to use Git as your version control system. After getting acquainted with the basic commands, we will look at how you can put your code on GitHub.

This article will cover the basics - how to initialize a project, how to manage new and existing files, and how to store your code in the cloud. We'll omit some tricky stuff like branching since this article is aimed at beginners.

Installing Git

The official Git website is available for various systems - Linux, Mac, Windows. In our case, we will be using Ubuntu 13.04 and we will be installing Git via apt-get .

sudo apt-get install git

Initial configuration

Let's create a directory in which we will work. You can also use Git to work on an existing project, in which case you won't create a demo directory as described below.

mkdir my_git_project cd my_git_project

The first step is to initialize the Git repository in the project directory. You can do this with the init command, which creates a .git directory with all the information about your project.

Git config --global user.name "Shaumik" git config --global user.email " [email protected]" git config --global color.ui "auto"

It's worth noting that if you don't include your address and name, the default values ​​will be used instead. In our case, the default values ​​will be donny and [email protected]

We also set the interface color to auto , so that the output of Git commands will be colored. We add the --global prefix to these commands so that these values ​​are used throughout the system and do not need to be set for each individual project.

Preparing files for commit

The next step is to create some files. You can use any text editor for this. Note that if you are initializing Git on an existing project, you do not need to take this step.

Checking the status of the repository

Now that you have files in your project, let's take a look at how Git handles them. To check the current status of a repository, use the git status command

Adding files to Git

At this point, Git isn't monitoring any of our files. You need to specifically add files to Git for this to happen. To do this, we use the add command.

Git add my_file

After checking the status of the repository, we see that one of the files has already been added to it.

To add multiple files, use the following (note that we added the first file earlier, so we only add the remaining two).

Git add myfile2 myfile3

It is possible to use git add recursively, but be careful with this command. There are some files (like compiled programs) that should not be added to source control. If you use git add recursively, these files will also be added to the repository.

Delete files

Let's imagine that you accidentally added a file to the repository that should not have been there. Or you want to remove a file from the version control system. In general, the git rm command will not only remove a file from the repository, but also physically remove it from the disk. To make Git stop tracking a file but keep it on disk, use the following command:

Git rm --cached [filename]

Commit changes

Once you have added all the necessary files, you can commit (commit) them to Git. Think of a commit as a snapshot of the state of the project at a certain stage, to which you can return at any point in time and see the state of the project at that moment. Each commit has a message associated with it, which is given as an argument after the -m prefix

Git commit -m "My first commit"

Specify a message that will contain useful information, as they help to understand what exactly was changed within this commit. Avoid any general messages like "Rules of bugs". If you have a bug tracker, you can specify a message like "Fixed bug #123". It is good practice to include the name of the branch or improvement in the message. For example, “Asset Management - Added the ability to generate PDF based on an asset” is a clear and understandable message.

Git identifies a commit with a long hexadecimal number. Usually, it is not necessary to copy the entire line, the first 5-6 characters are enough to identify a particular commit. From the screenshot, you can see that our commit is identified by the number 8dd76fc .

Further commits

Let's change some files after we've committed them. After we have changed them, git status will report that we have changed files.

You can see what has changed in these files since the previous commit with the git diff command. If you want to see the changes for a particular file, you can use git diff<файл> .

It is necessary to index the changes and commit them. All changed project files can be added to a commit with the following command:

You can avoid using this command by adding the -a option to git commit . This command will index all modified files and commit them. But this approach can be quite dangerous, as you can mistakenly commit something that you didn’t want to. For example, let's say you open a file and you accidentally change it. When indexing modified files, you will be notified of changes in each file. But if you commit all changed files without looking at help. git commit -a , then all files will be committed, including those that you did not want to commit.

Once you have indexed the files, you can start committing. As mentioned earlier, you can specify a message for a commit using the -m switch. But you can also specify multi-line comments with the git commit command, which opens a console editor to enter a comment.

Project Management

To view the history of a project, you can use the following command:

It will display the complete history of the project in the form of a list of commits and information about them. The commit information contains the commit hash, author, time, and commit message. There are many kinds of git log commands that you will need to become familiar with when branching in Git. To see the details of a particular commit, and the files that have changed, run the following command:

Git show<хеш_коммита>

Where<хеш_коммита>is the hexadecimal number associated with the commit. Since this guide is for beginners, we won't cover how to revert to the state of a particular commit, or how to manage branches.

Most of you have probably heard of the git version control system. Today we will look at the whole path from installing git to making our changes to a remote repository using the OsEngine library as an example. First, download the git client from the link and install it. Questions will not arise
should, just click Next everywhere. Further interaction with git will be considered using the example of working with the console client. The next step is to register on the website https://github.com/ . Now we can join the work on OsEngine. To do this, go to the project repository and click the Fork button in the upper right corner.

With this action, we created a fork (in other words, a branch), which is stored in the repository of our account and now we can make changes to it without fear of breaking something in the main branch of the project. Further, this very our repository on github we will call the remote repository.
Now let's get started with git itself and the first thing we need to do is create a local copy of the remote repository on our computer. To do this, go to the desired folder, select the Git Bash Here item in the context menu and the console will open.

$ git clone "insert unquoted link here"

The process of copying the remote repository to the local one will begin, and a working copy with the name OsEngine will appear in the current folder.

Working with a local repository

git setup

Before you start working with git, you need to set it up. Open git bash, set login and password with commands:

$ git config --global user.name "your name"
$ git config --global user.email "your email"

The following command allows you to view the configuration file:

$ git config --global --list


Working with branches

Branches in git are the same as branches on github. To create a new branch, run the command in the console:

$ git branch desired name

To switch to this branch, run the command:

$ git checkout branch name

to return to the main branch, type:

$ git checkout master

rename branch:

$ git branch -m new name

team $ git branch allows you to determine which branch we are currently in. Deletes a branch command

$git branch –D branch name

Merging a branch with the main one is done with the command:

$ git merge branch name

When merging branches in which the same files are changed differently, a conflict may arise and the merger will not occur. To get out of this situation, you need to fix these files properly.

Commits

The whole point of using git is in commits. A commit is a so-called snapshot of the state of the project at a certain stage.
development. For example: we have the OsEngine library, we added to
it a new indicator and committed, then decided to correct some file in
engine and after that the application crashes or does not want to work correctly. To
not to do extra work and not to correct everything back, we can simply
rollback to a previous commit when the application worked as it should. Respectively
all work with git revolves around creating, deleting, editing, merging
commits and branches.


Adding files to the index

Suppose we have added a README file to the project, but before committing, we need to add the changed files to
index, the so-called temporary storage of changes. This is done as follows: if you need to index one file, then we execute

$ git add README

and the README file will be added to the index, if you need to index all updated and new files, then execute

$ git add .

Note that it is with a dot at the end and a space before it.

Removing files from the index

If you accidentally indexed an unnecessary file, then the git reset command will help you remove it from the index, for example, remove the README file from the index:

$git reset README

If you change your mind about keeping the changes made to the file, run the command

$ git checkout -- filename

and it will return to the state it was in at the time of the last commit, just keep in mind that all changes to this file will be gone.

Create a commit

Now you can commit the changes, this is done using the command:

$ git commit –m “There should be a quoted comment here”

It should be remembered that the presence of a comment is a prerequisite. The history of changes can be viewed with the command

$ gitlog

$ git show will show only the latest changes. Press q to exit playback mode.

Git has the ability to index all changes and commit with one command:

$ git commit -a -m "comment in quotes"

A means: add all changes to the index before commit.
-m: comment.


Editing, deleting, commit

If you need to undo the last commit, use the command:

$ git revert HEAD

Commits are counted from 0 starting from the last one, for example, if you need to undo the third commit, you should run:

$ git revert HEAD~2

Team $ git reset --soft HEAD~3 will remove the last 3 commits and roll back the project to the state of the fourth commit, while keeping all the changes of the last three commits in the index.

$ git reset -- hard HEAD~3

will completely remove the last three commits.

File Status

$ git status - the main command that monitors the status of files. It shows whether there are changes in monitored files or if there are unmonitored files. Tracked files are those files that are in the previous commit. If we added a new file to the project, then it will be considered untracked.


Making local changes to a remote repository


Now that the necessary changes have been made to the local repository, they can be uploaded to the remote repository.
This is done by running the command:

$ git push origin master

In this case, you will need to enter the login and password from github. However, the download may not occur. The reason may lie in the fact that there are changes in the remote repository that are not in the local one. To get out of the situation, you need to pick up these new
changes to the local repository with the command:

$git-pull



Using SSH Keys


To get rid of the need to enter a login and password every time when sending changes to a remote repository, you can use SSH keys. First, you need to generate the keys by running the command:

$ ssh-keygen

Then press enter 3 times and in the default directory C:\Users\username\.ssh a folder with keys will appear. Need to open a file
id_rsa of type PUB in any text editor and copy its content. Then go to github in your account settings

After that, in the column on the left, select the item: SSH and GPG keys and press the green button on the right New SSH key

set the Title, in the Key field paste the data copied from the key and click

Merging branches on github


After you have made all the necessary changes to your remote repository, you can submit a pull request to the main repository of the OsEngine project. Just click the New pull request button

and then

In this article, we have covered the basic git commands, they are enough to start working on the OsEngine project using git and the github service.

Happy commits!

It is natural for people to resist change. If Git wasn't your thing when you first started working with version control systems, you're probably more comfortable with Subversion (SVN) .

Often people say that Git is too complicated for beginners. However, I beg to differ with this.

In this tutorial, I'll show you how to use Git in your projects. Let's say you're building a project from scratch and want to manage it with Git . Walking through the list of basic commands will give you an idea of ​​how to host your code in the cloud using GitHub.

In this article, we'll talk about the basics of Git - how to initialize your projects, how to manage new and existing files, and how to store your code in the cloud.

We won't touch on the relatively complex parts of Git, such as branching, as this tutorial is for beginners.

Installing Git

The official Git website has detailed information about installing it on Linux, Mac and Windows. In our case, we will be using Ubuntu 13.04 for demonstration purposes, where we will install Git using apt-get:

sudo apt-get install git

Initial setup

Let's create a directory we'll work inside. Alternatively, you can use Git to manage one of your existing projects; in this case, you will not need to create a demo directory, as shown below:

mkdir my_git_project cd my_git_project

The first step is to initialize Git in the directory. This can be done with the init command, which creates a .git directory containing all the Git-related information for your project.

git config --global user.name "Shaumik" git config --global user.email " [email protected]" git config --global color.ui "auto"

It's important to note that if you don't enter your name and email address, the default values ​​will be used. In our case, the default values ​​would be the username donny and the email address. [email protected].

We're also setting the UI color to auto , which causes Git command output to be color-coded.

The --global prefix in front of the commands is to avoid having to type these configuration commands the next time we run a Git project on our system.

Preparing files for commit

The next step is to create the files in the directory. You can use, for example, the Vim text editor. Note that if you're going to add Git to an already existing directory, you don't need to do this step:

Check repository status

Now that we have a few files in our repository, let's take a look at how Git handles them. To check the current status of a repository, use the git status command:

Adding files to Git for tracking

We don't have any files to track with Git at the moment. We need to add files specifically to Git in order to tell Git what to track.

Add files using the add command:

Checking the repository status again, we can see that one file has been added:

To add multiple files, you can use the following command entry (note that we have added one more file for demonstration purposes):

git add myfile2 myfile3

You can use git add recursively, but be careful with this command. There are certain files (such as compiled files) that are usually stored outside of a Git repository.

If you use the add command recursively, it will add all such files if they exist in your repository.

Deleting files

But running a simple git rm command will remove the file not only from Git , but from your local file system as well! To

Git has stopped tracking the file, but the file itself is still on your local system, run the following command:

git rm --cached

Commit changes

After you have placed your files, you can commit them to Git . Think of a commit as capturing a specific moment that you can go back to to access your repository at that point.

You can attach a message to each commit, which is prefixed with -m :

git commit -m "My first commit"

Provide useful commit messages because it will help you identify what you have changed in that commit.

Avoid overly general messages like " Bugs fixed". If you have an issue tracker, you can add messages in the form " Bug #234 fixed».

It is good practice to use the branch name or feature name as a prefix to the commit message. For example, " Asset Management: Added feature to generate PDF asset files' is a meaningful message.

Git identifies commits by adding a long hexadecimal number to each commit. As a rule, you do not need to copy the entire line, the first 5-6 characters are enough to determine your commit.

Note that in the screenshot, our first commit is identified by 8dd76fc .

Further commits

Now let's change a few files after our first commit. After changing them, we will see that as a result of running the git status command, Git found changes in the files it is tracking:

You can check the changes in tracked files made in the last commit with the git diff command. If you want to see the changes in a specific file, use the git diff command :

You need to add these files again in order to make changes to the tracked files for the next commit. You can add all monitored files by running the command:

You can avoid using this command by using the -a prefix for the git commit command, which will add all changes to tracked files.

This process, however, is very dangerous, as it can harm the project. For example, let's say you opened a file and changed it by mistake.

If you selectively place files, you will notice changes in each file. But if you add the -a prefix to your commit, all files will be committed and you won't be able to detect possible errors.

Once you've placed your files, you can start committing. I mentioned that each commit can have a message associated with it, which we prefix with -m .

However, it is possible to enter a message on multiple lines using the git commit command, which opens an interactive write form:

Project management

To view the history of your project, you can run the following command:

This will show the entire history of the project, which is a list of all commits and information on them. The commit information includes the commit hash code, the author, the time, and the commit message. There are various variations of git log that you can explore once you've mastered the concept of a branch in Git.

To view detailed information about a specific commit and the files that have changed, run the following command:

git-show

Where is the hexadecimal number associated with the commit. Since this tutorial is for beginners, we won't cover how to revert back to the state of a particular commit or how to manage branches.

Hosting code in the cloud

Now that you've learned how to manage the code on your system, it's time to host your code in the cloud.

Distributed version control systems (DVCS) are gradually replacing centralized ones. If you're not using one of them yet, now is the time to try it.

In this article, I will try to show how you can quickly start experimenting with git using the github.com site.

This article will not cover the differences between different DVCSs. Also, working with git will not be considered in detail, there are many good sources on this topic, which I will cite at the end of the article.

So, the github.com site is positioned as a web service for hosting projects using the git version control system, as well as a social network for developers. Users can create an unlimited number of repositories, for each of which a wiki is provided, an issue tracking system, it is possible to conduct code reviews and much more. GitHub is currently the most popular service of its kind, overtaking Sourceforge and Google Code.

For open-souce projects, the use of the site is free. If you need to have private repositories, you can upgrade to a paid plan:

Let's start with registration. Follow the link github.com/signup/free and enter your details.
After registration, we get to the Dashboard of our account:

Right now we don't have a single repository, and we can either create a new repository, or branch (fork) from an already existing someone else's repository and maintain our own development branch. Then, if desired, you can offer your changes to the author of the original repository (Pull request).

But first, let's install git and configure it to work with the site.

If you are on Windows, download and install msysgit . This is the console version of git for Windows (further the story will be based on the example of this OS).
Instructions for MacOS X (eng)
Instruction for Linux (eng)
There should be no problems, just click Next everywhere. After installation, select Git Bash Explorer from the context menu:

Or via Git Bash.lnk in the folder with the installed program:

We write our data and line break settings in the console:
git config --global user.name "your name"
git config --global user.email "your mail"
git config --global core.autocrlf true
git config --global core.safecrlf true

By the way, I recommend taking a good interactive course on using git from the console. The course is completed in a few hours and provides the necessary basic skills.

For those who prefer the gui, there are several such tools for working with git for Windows. The two main ones are SmartGit (cross-platform) and TortoiseGit. Both are good, and which one to use is a matter of taste. I will describe working with TortoiseGit.
For poppies, there is also a choice of giu.

  • the official client from GitHub - in my opinion, it is still rather damp.
  • GitX - I personally did not like
  • GitBox - the most followed mac-way, I highly recommend trying it

About git in Russian:
habrahabr.ru/blogs/Git/106912 "Successful branching model for git" - translation of a good English article
githowto.com interactive course on working with git from the console
habrahabr.ru/blogs/Git/106912 "Why git" + discussion
habrahabr.ru/blogs/development/68341 "Git for transitioning from SVN" + discussion

Distributed version control systems (DVCS) are gradually replacing centralized ones. If you're not using one of them yet, now is the time to try it.

In this article, I will try to show how you can quickly start experimenting with git using the github.com site.

This article will not cover the differences between different DVCSs. Also, working with git will not be considered in detail, there are many good sources on this topic, which I will cite at the end of the article.

So, the github.com site is positioned as a web service for hosting projects using the git version control system, as well as a social network for developers. Users can create an unlimited number of repositories, for each of which a wiki is provided, an issue tracking system, it is possible to conduct code reviews and much more. GitHub is currently the most popular service of its kind, overtaking Sourceforge and Google Code.

For open-souce projects, the use of the site is free. If you need to have private repositories, you can upgrade to a paid plan:

Let's start with registration. Follow the link github.com/signup/free and enter your details.
After registration, we get to the Dashboard of our account:

Right now we don't have a single repository, and we can either create a new repository, or branch (fork) from an already existing someone else's repository and maintain our own development branch. Then, if desired, you can offer your changes to the author of the original repository (Pull request).

But first, let's install git and configure it to work with the site.

If you are on Windows, download and install msysgit . This is the console version of git for Windows (further the story will be based on the example of this OS).
Instructions for MacOS X (eng)
Instruction for Linux (eng)
There should be no problems, just click Next everywhere. After installation, select Git Bash Explorer from the context menu:

Or via Git Bash.lnk in the folder with the installed program:

We write our data and line break settings in the console:
git config --global user.name "your name"
git config --global user.email "your mail"
git config --global core.autocrlf true
git config --global core.safecrlf true

By the way, I recommend taking a good interactive course on using git from the console. The course is completed in a few hours and provides the necessary basic skills.

For those who prefer the gui, there are several such tools for working with git for Windows. The two main ones are SmartGit (cross-platform) and TortoiseGit. Both are good, and which one to use is a matter of taste. I will describe working with TortoiseGit.
For poppies, there is also a choice of giu.

  • the official client from GitHub - in my opinion, it is still rather damp.
  • GitX - I personally did not like
  • GitBox - the most followed mac-way, I highly recommend trying it

About git in Russian:
"A good branching model for git" - translation of a good English article
githowto.com interactive course on working with git from the console
"Why git" + discussion
"Git for migrating from SVN" + discussion

mob_info