Easy Tutorial
❮ Chrome Skip Android Tutorial Progressbar ❯

Git Five-Minute Tutorial

Category Programming Technology

Many people think Git is too chaotic or believe it is a complex version control system, but that's not the case. This article helps you quickly get started with using Git.

Getting Started

Before using Git, you need to create a repository. You can use an existing directory as a Git repository or create an empty one.

To use your current directory as a Git repository, we just need to initialize it.

git init

To use a specified directory as a Git repository.

git init newrepo

From now on, we will assume you are in the root directory of the Git repository unless otherwise specified.

#

We have a repository, but it's empty. You can use the add command to add files.

git add filename

You can continue to add task files with add...

#

Now that we have added these files, we want them to be truly saved in the Git repository.

To do this, we will commit them to the repository.

git commit -m "Adding files"

If you don't use -m, an editor will appear for you to write your own comment message.

When we have modified many files and don't want to add each one individually, we can use the -a flag to automatically commit local changes.

git commit -a -m "Changed some files"

The -a option of the git commit command can commit all modified or deleted files that are already managed by git to the repository.

#

We will first clone a repository from the server and upload changes.

git clone ssh://example.com/~/www/project.git

Now we can push our changes to the server after modifying.

git push ssh://example.com/~/www/project.git

#

If you have pushed as described above, the following command indicates that the current branch will automatically merge with the only tracked branch.

git pull

To update from a specified URL instead of the default location.

git pull http://git.example.com/project.git

Has it been more than five minutes?

#

If you want to remove a file from the repository, we use rm.

git rm file

#

Branching is done locally and is fast. To create a new branch, we use the branch command.

git branch test

The branch command does not switch us to the branch, it just creates a new one. So we use the checkout command to change branches.

git checkout test

The first branch, or main branch, is called "master".

git checkout master

Changes in other branches will not reflect in the master branch. If you want to commit changes to the master branch, you need to switch back to the master branch and then use merge.

git checkout master
git merge test

If you want to delete a branch, we use the -d flag.

git branch -d test

Related Articles

>

Source: http://itmyhome.com/2015/01/git-five-minutes-tutorial

** Click to Share Notes

Cancel

-

-

-

❮ Chrome Skip Android Tutorial Progressbar ❯