diff --git a/doc/gitlab-basics/basicsimages/git_version_cli.png b/doc/gitlab-basics/basicsimages/git_version_cli.png new file mode 100644 index 0000000000000000000000000000000000000000..712219e3eac6f982d603f7074f72fd521c0809ab Binary files /dev/null and b/doc/gitlab-basics/basicsimages/git_version_cli.png differ diff --git a/doc/gitlab-basics/start-using-git.md b/doc/gitlab-basics/start-using-git.md index 89ce8bcc3e88b217cb18362942f036da66fa9bf2..e18599fea024b4118ee68d1eec03a765d2d8abf9 100644 --- a/doc/gitlab-basics/start-using-git.md +++ b/doc/gitlab-basics/start-using-git.md @@ -1,13 +1,17 @@ -# Start using Git on the command line +# Start using Git on the command-line -If you want to start using a Git and GitLab, make sure that you have created an -account on GitLab. +To start using GitLab using the command-line, you will need the following: +- [An account](https://gitlab.com/users/sign_in) on GitLab. +- A shell to access Git's functionality using the command-line. +- The Git command-line program; either as an individual program or as a part of the shell itself. ## Open a shell -Depending on your operating system, find the shell of your preference. Here are some suggestions. +Fire up the shell of your preference. -- [Terminal](http://blog.teamtreehouse.com/introduction-to-the-mac-os-x-command-line) on Mac OSX +Below are some of the popular options on OS X, Windows and Linux. + +- [Terminal](http://blog.teamtreehouse.com/introduction-to-the-mac-os-x-command-line) on OS X - [GitBash](https://msysgit.github.io) on Windows @@ -15,24 +19,27 @@ Depending on your operating system, find the shell of your preference. Here are ## Check if Git has already been installed -Git is usually preinstalled on Mac and Linux. +Git is often pre-installed on OS X and Linux. -Type the following command and then press enter: +To check if that is the case, type the following command into the shell and then press enter: ``` git --version ``` +If Git is installed, you should see a message that will tell you which Git version you have in your computer. + +![git --version command](basicsimages/git_version_cli.png) -You should receive a message that will tell you which Git version you have in your computer. If you don’t receive a "Git version" message, it means that you need to [download Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git). +If you don’t receive a "Git version" message, it means that you need to [install Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) on your operating system. -If Git doesn't automatically download, there's an option on the website to [download manually](https://git-scm.com/downloads). Then follow the steps on the installation window. +You can also install Git using one of the [official installers](https://git-scm.com/downloads). -After you finished installing, open a new shell and type "git --version" again to verify that it was correctly installed. +Once you have finished installing Git, open a new shell and type "git --version" once again to verify that it was correctly installed. ## Add your Git username and set your email -It is important because every Git commit that you create will use this information. +Every Git commit that you create will show your username and email. Therefore, it is important to set this properly. -On your shell, type the following command to add your username: +In your shell, type the following command to add your username: ``` git config --global user.name ADD YOUR USERNAME ``` @@ -51,8 +58,9 @@ To verify that you entered your email correctly, type: ``` git config --global user.email ``` +Using the "--global" option means that you need to set this information only once. After this, Git will always use this information everywhere. -You'll need to do this only once because you are using the "--global" option. It tells Git to always use this information for anything you do on that system. If you want to override this with a different username or email address for specific projects, you can run the command without the "--global" option when you’re in that project. +If you want to override this with a different username or email address for specific projects, you can run the command without the "--global" option when you’re in that project. ## Check your information @@ -62,6 +70,8 @@ git config --global --list ``` ## Basic Git commands +Let us go through some of the basic Git commands. + ### Go to the master branch to pull the latest changes from there ``` @@ -69,14 +79,14 @@ git checkout master ``` ### Download the latest changes in the project -This is for you to work on an up-to-date copy (it is important to do every time you work on a project), while you setup tracking branches. +This is for you to work on an up-to-date copy (it is important to do this every time you work on a project), while you setup tracking branches. ``` git pull REMOTE NAME-OF-BRANCH -u ``` -(REMOTE: origin) (NAME-OF-BRANCH: could be "master" or an existing branch) +A good example for REMOTE could be 'origin' and the NAME-OF-BRANCH could be 'master' or an existing branch. ### Create a branch -Spaces won't be recognized, so you need to use a hyphen or underscore. +Spaces are not valid in naming branches. You can to use a hyphens or underscores as separators in their place. ``` git checkout -b NAME-OF-BRANCH ``` @@ -86,16 +96,23 @@ git checkout -b NAME-OF-BRANCH git checkout NAME-OF-BRANCH ``` -### View the changes you've made -It's important to be aware of what's happening and what's the status of your changes. +### View the changes you have made +Before you start the process to commit your changes, it is important to review the changes you have made. ``` git status ``` - ### Add changes to commit -You'll see your changes in red when you type "git status". +Git will highlight all untracked changes in red when you type "git status". + +To add any of the files shown in red to the commit, you have to use the following command: +``` +git add FILENAME +``` + +Once you have added the files, commit them with a message that describes the intention of the commit. + +This will help others understand easily what is the purpose of the commit. ``` -git add CHANGES IN RED git commit -m "DESCRIBE THE INTENTION OF THE COMMIT" ``` @@ -115,7 +132,7 @@ git clean -f ``` ### Merge created branch with master branch -You need to be in the created branch. +You need to be in the created branch to successfully complete this operation. ``` git checkout NAME-OF-BRANCH git merge master