文档章节

Git Commands Ultimate Tutorial [Part 2]

Kolosek
 Kolosek
发布于 2018/04/11 17:31
字数 847
阅读 5
Git">收藏 0

In the last Git Commands article, we have learned how to use Git options and what they can do. Today, we will extend our reach and discover everything there is to know about commonly used Git Commands.

Git Commands

Git commands are used to access the Git working directory and connect it to our remote repository, by making changes, viewing different files, and many other possibilities! Once your project is set, be sure to connect it with Git.

With the following commands and short descriptions, we will make it sure that you are ready to use Git whenever you need it. For a detailed description of all, the GIT commands please check git's official description.

$git config
You can use it to configure the author's name, email address, file formats and many more to be used with your commits.

git config --global user.name "Kolosek
git config --global user.email "kolosek@example.com"

$git init
Using this command you make it sure that your git repository is initialized and creates the initial .git directory in a new or in an existing project. The output will be the following:

Initialized empty Git repository in /path/.git/

You can undo a $git init with rm -rf .git.

$git clone <path>
This creates a working copy of a Git repository from a remote source to your local repository. This is the first command you want to use when you are cloning a Git repository.

git clone /path/repository

Also, you can add the original location as a remote so you can easily fetch from it again and push it if you have permissions. Once the project has been cloned you can start working on it. Write your RSpec tests!

git clone git@github:user/repository.git

You can clone one specific branch at a time: git clone -b <branch_name><repository_url>:

git clone -b branch_name git@github:user/repository.git

$git add <file_name>
Add one or more files in your working directory to your index.

$git commit
Take all your changes written in the index to the HEAD branch with a -m message.

git commit -m "Commit these changes."

You can also commit any files you've added to git add, and also commit any files you've changed since then:

git commit -a

Always commit all your changes even if its only a bunch of Capybara tests!

$git status
It shows you the status difference between an index and working directory files. Lists the files you've changed, untracked because they are only in your working directory and staged since they are ready to be committed.

On branch master
Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    File_name

nothing added to commit but untracked files present (use "git add" to track)

$git remote
Shows all the remote versions of your repository.

$git checkout <branch_name>: You can switch from an existing branch to another one or create a new branch and switch to it git checkout -b <branch_name>.

$git branch
With this, you can simply list all existing branches, including remote branches by using -a or create a new branch if a branch name is provided.

$git push
Pushes all changes to the remote repository.

git push origin <branch_name>

You can also delete a branch from your remote repository:

git push origin :<branch_name>

$git pull
Fetch and merge your changes in the remote repository to your working directory.

$git merge <branch_name>
Merges one or more branches into your active branch and if there are no conflicts it will automatically create a new commit.

In Kolosek we commit all our changes to Git and make it sure to notify our team when they are merged with the rest of the application! Try to create your own application using Rails Associations.

$git diff
Show changes between your working tree and the index, between two branches, or changes between two files on disk. Example between branches:

git diff <source_branch> <target_branch>

$git reset
Reset your index and working directory to the state of your last commit.

git reset --hard origin/master

git reset --hard will also undo the changes you made so far! Use git reset --soft if you want to keep your changes

$git revert
Revert works in a very similar way to $git reset, but instead of resetting it will create a new commit that reverses everything introduced by the accidental commit.

$git tag
You can use tagging to mark a significant change you made, such as a release.

git tag 1.0.0 <commit_id>

Always tag your new production releases. Try it out by implementing CarrierWave and adding a release tag to it!

$git log
It shows a listing of commits on a branch with corresponding details.

commit 134808af7c596be8d92c619f9efb94542874e1e3
Author: Kolosek <kolosek@example.com>
Date:   Fri Mar 23 14:24:54 2018 +0100

    [#1] First Commit

Conclusions

With this, we have covered everything there is to know about Git commands. Don't forget, these are only the very basic and most commonly used commands. Hope this helped you to get started with Git!

This post is originally published on Kolosek Blog.

© 著作权归作者所有

Kolosek
粉丝 0
博文 29
码字总数 20461
作品 0
塞尔维亚
CEO
私信 提问
CI/CD Pipeline Using GitHub, Docker, CircleCI, and Heroku

This post will walk you through how to setup a Continuous Integration & Continuous Deployment (CI/CD) pipeline with CircleCI, Docker & Heroku easily. In the end of this tutorial......

Mohamed Labouardy
2017/12/21
0
0
Installing Odoo 8 on CentOS 6 with Python 2.7

This tutorial will walk you through the process of installing the latest version of Odoo on CentOS 6. It is intended for those who might not be experienced Linux administrators ......

Ericklee
2015/02/10
0
0
Vim实战手册(1)初级个性化配置你的Vim

转载请注明本篇博文来自“柳大CSDN博客”:http://blog.csdn.net/poechant 1、VIM是什么? VIM是Vi IMproved,是编辑器Vi的一个加强版,一个极其强大并符合SE(Software Engineer,软件工程师...

晨曦之光
2012/04/24
105
0
英文PDF文档分享:包括 Python、Ruby、MySQL 等等

Tutorials in PDF Format: Python Tutorial in PDF - Download quick Python tutorial in PDF format. Ruby Tutorial in PDF - Download quick Ruby tutorial in PDF format. Java Tutorial ......

红薯
2011/06/06
857
1
LER0ever/EverVim

EverVim: The Ultimate Vim Distribution | About | Installation | Features | ScreenShots | Documentation! | License | About EverVim is the ultimate vim distribution that supports ......

LER0ever
2017/04/14
0
0

没有更多内容

加载失败,请刷新页面

加载更多

3_数组

3_数组

行者终成事
19分钟前
2
0
经典系统设计面试题解析:如何设计TinyURL(二)

原文链接:https://www.educative.io/courses/grokking-the-system-design-interview/m2ygV4E81AR 编者注:本文以一道经典的系统设计面试题:《如何设计TinyURL》的参考答案和解析为例,帮助...

APEMESH
今天
7
0
使用logstash同步MySQL数据到ES

概述   在生成业务常有将MySQL数据同步到ES的需求,如果需要很高的定制化,往往需要开发同步程序用于处理数据。但没有特殊业务需求,官方提供的logstash就很有优势了。   在使用logstas...

zxiaofan666
今天
10
0
X-MSG-IM-分布式信令跟踪能力

经过一周多的鏖战, X-MSG-IM的分布式信令跟踪能力已基本具备, 特点是: 实时. 只有要RX/TX就会实时产生信令跟踪事件, 先入kafka, 再入influxdb待查. 同时提供实时sub/pub接口. 完备. 可以完整...

dev5
今天
7
0
OpenJDK之CyclicBarrier

OpenJDK8,本人看的是openJDK。以前就看过,只是经常忘记,所以记录下 图1 CyclicBarrier是Doug Lea在JDK1.5中引入的,作用就不详细描述了,主要有如下俩个方法使用: await()方法,如果当前线...

克虏伯
今天
8
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部