LoginSignup
2
0

More than 5 years have passed since last update.

【Git】git tutorial for beginner

Last updated at Posted at 2017-06-12

This document is for BEGINNERS!!

1. 【Git command flow】

Git flow is below.
You MUST remember this.

# check your status
1. git status

# upload modified file to staging area
2. git add .

# commit changes
3. git commit -m "commit massage"

# check your commit log
4. git log
(If you want to **exit** type q.)

スクリーンショット 2017-06-12 14.30.33.png
("blue" is git command)

2. 【Output】 git status command

This chapter shows input/output of git status.

  1. not git repository
  2. nothing to change
  3. pre-add(need to add)
  4. pre-commit(need to commit)

(1). not git repository

スクリーンショット 2017-06-12 12.46.00.png

This output says "Not a git repository".
You may be in different directory or have not initialized git. Check current directory.

# check current directory command
pwd

If you are in the correct position to track git, you should type initialize command.

git init

(2). nothing to change

スクリーンショット 2017-06-12 13.28.45.png

This output says "nothing to change".
There are two following possibilities.
(1) You already commited the changes.
(2) You haven’t saved local file changes.

Check your local file!!

(3). pre-add

スクリーンショット 2017-06-12 11.17.32.png

This output says "Local file is modified. Need to add or stash".
If you want to track local file, you should add the files.

# "." means all-file
git add .
# or
git add file-name

(4). pre-commit

スクリーンショット 2017-06-12 13.10.23.png

This output says “Your changes are already added for staging”..
So you should commit your changes.

# "-m" means message
git commit -m "your change log message"
# or
git commit

3. 【Other commands & settings】

[command] add remote

If you want to add remote repository, you should type this command.

# add remote repository
git remote add origin remote-repository path
# For example
#  git remote add origin git@bitbucket.org:banaoh/toy_app.git

[command] delete remote

If you don't want to add wrong remote repository, you should type below.

# check your set remote path
git remote -v

# if the path wrong
git remote rm origin

[alias] shortcut git command

If you get stress to type full command, you set alias.
"alias" are like shortcut :).

vim ~/.gitconfig

# and

[alias]
    st = status
    ci = commit
    co = checkout
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0