Skip to content

AlirezaKhodabakhsh/git-tutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Git & GitHub Tutorial


visitors

List of Content:


Linux commands


Current directory

Write about it.

pwd

Change directory

cd [options]

Options:

  • <root> :
  • .. : Navigate back folder.
  • ../.. : Navigate twice back folder.
  • <folder_name> : Navigate forward folder.

Make new folder

Write about it.

mkdir [options]

Options:

  • <folder_name> : Create new folder.

List current folder contents

Write about it.

ls [options]

Options:

  • notthing : List file(s) in current directory.

Make new file

touch [options]

Options:

  • <file_name>+<format+name> : Create file with desired format.

Clear terminal

clear [options]

Options:

  • nothing : clear terminal display.

Literature review


Working tree

  • The working tree, or working directory, consists of files that you are currently working on.
  • You can think of a working tree as a file system where you can view and modify files.

Commit

  • save your file/files that put in stage, and after commit, git consider this file/files as a HEAD file. You will be availble call every commit in future.
  • Git considers each commit change point or "save point". It is a point in the project you can go back to if you find a bug, or want to make a change.

Stage

  • stage is a place that, 1. untracked files put in stage in order to in commit phase, tracked by git. or 2. modified/deleted/... files that already tracked by git, put in stage in order to save changed in commit phase.

Tracked/Untracked file

  • you have NEW file/files that if contents modified, git can't sense alterations.
  • Untracked basically means that Git sees a file you didn't have in the previous snapshot (commit), and which hasn't yet been staged.
  • Untracked files are most of the time files you don't want to be controlled, because for example they are generated by your compiler.
  • Tracked - files that Git knows about and are added to the local repository.
  • Untracked - files that are in your working directory, but not added to the local repository.

Modifed file

  • git always check tracked file/files,when file/files contents has been changed, git label it/these to modified file.

Nothing added to commit

  • no file/files are in stage to commit.

Changes not staged for commit

  • your tracked file/files has been modified, and NOT yet put in stage to commit.

HEAD

  • HEAD is last/final commit (last saved alterations).

Local

  • local meaning is in your personal computer.
  • EX:
    local commit : a written commit that has been write in your computer and has not yet push in remote repository.

Origin

  • origin" is the name of the remote repository where you want to publish you commits. By convention, the default remote repository is called "origin", but you can work with several remotes (with different names) as the same time. More information here.

Remote

  • A remote repository in Git, also called a remote, is a Git repository that's hosted on the Internet or another network.

Both modified

  • recommend you : commit and merege early early!
  • recomend you : pull repository, and edited it and commit and push it.

Clone

  • duplicate and download everything of remote repository when you use command clone in git, git create new folder with name as same as name of remote repo in github and copy and download everything and put it them on this folder.

Ahead of origin/master

Behind of origin/master

  • when you fetch remote repo on your local repo, this guide say you, remote repo have new commits so that you have not these commits in your local repository. and you "behind of origin/master" this meaning that, you are NOT update rather to origin remote on master branch.

Your branch is up to date

  • when pull (fetch and merge) remote branch with your local branch this guide showed.

Origin/master & master

  • "remote name"/"remote branch name" & "local branch name"

Tag

  • Git has the ability to tag specific points in a repository’s history as being important.

Local repository


Directory

Write about it.

Initialize git

Count current directory to git and git folder create in current directory:

git init

Display status

Summery alterations in some frequent phrases:

git status [options]

Options:

  • --short : Summery commit shortly

Frequent phrases:
Tracked file/files
Untracked file/files
Staged file/files
Unstaged file/files

NOTE:
git status show only just alterations in local repository and not show alterations in remote repository. This means that, if anyone had been changed some file(s) of remote repository (GitHub), git status would not show it to you.

Track / Stage

This command has two performance:

  • Track new file/files that not yet added to git.
  • Stage file/files that has been tracked by git.
git add [options]

Options:

  • <file_name> : Stage/Track file(s)
  • *.py : Stage/Track all .py file(s)
  • --all / -A : Stage/Track all file(s)
  • modules* : Stage/Track all file(s) that name start with module

Save alterations

Save(Commit) your staged/tracked file(files) with message:

git commit -m "<your message>"

NOTE:
Message is require.

Display commits

Show all commits:

git log

NOTE: If list of commit is long, you can press q to exit.

Display differences

Write about it.

git diff [options]

Options:

  • <nothing>:
  • HEAD:
  • --staged:

Branches

Write about branches.

git branch [options]

Options:

  • nothing: Show current branch
  • <branch_name>: Create new branch
  • -d <branch_name>: Delete branch

Checkout in branch

Write about checkout

git checkout <branch_name>

Merging

Write about merging

git merge <branch_name>

NOTE:
Sure that when you merge, your current branch in main branch.

Tagging

Write about it

git tag [options] -m "<tag_message>"

Options:

  • nothing : Show all tags yoy have.
  • -a <tag_name> : Tag HEAD commit (last commit)

NOTE:
a is annotation tag, if you didn't write it, you tag in lightweight tag.

  • -a <tag_name> <desired_commit> :

Checkout in tagging

Switch to desired tag.

git checkout <tag_name>

Remote repository


Remote

Write about remote

NOTE:
you can add multiple remotes and work with them at the same time.

git remote [options]

Options:

  • nothing : Show remotes (GitHub url) that you wish to push/pull your local repo commits to it).
  • add <remote_name> <remote_url> : Add new remote. This command simply means you are adding the location of your remote repository where you wish to push/pull your files. (e.g. git remote add asli "https://github.com/alirezakhodabakhsh/ hello")
  • rm <remote_name> : Remove specific remote.

Push to remote repo

If you had new commit(s) on your local remote, you can push these to remote repo:

git push [options]

Options:

  • <remote_name> <branch_name> :
  • <remote_name> --delete <branch_name> : Delete remote branch
  • <remote_name> <tag_name> : Push specific tag to your remote repo.

NOTE:
In this case, git status display:

Ahead of origin/master

This means that, you have new commit(s) than when you had pulled remote repo.

NOTE:
Recommend that current branch set on <branch_name> that you want to push it (local repo branch and remote repo branch be as same as).

NOTE:
If <branch_name> wasn't there in remote repository, new branch has been created.

Pull to local repo

Pull is combination of Fetch and Merge.

Fetch

Write about it.

git fetch [options]

Options:

  • <remote_name> :

Merge

Write about it

git merge [options]

Options:

  • <remote_name>/<remote_branch_name> : Merge remote branch
  • with your local branch.

Pull

Write about it.

git pull [options]

Options:

  • <remote_name> <remote_branch_name> : Fetch and Merge respectively from remote branch name on local branch name.

NOTE:
Recommended, current local branch as same as repo branch.

Differences

Write about it.

git diff [options]

Options:

  • <remote_name> <remote_branch_name> :Show difference master branch (remote repo) with master branch (local repo).

Clone to local repo

Clone remote repo:

git clone <remote_url>

Branches

Show local and remote branches.

git branch -a

NOTE:
If you pull and up-to-date local repo, new remote branches wouldn't put in your local branches. So you should use git checkout <remote branch> and use again git pull to up-to-date.


Conflict in Git/GitHub

Conflict in local repo

When you create new branch, you duplicate master branch files and work on them. At this time, if someone (you) change master branch file(s) and commit changes, after that, you merge branch with master branch, you get conflict. In this time, you must get rid of this conflict. and then merge and commit.

RECOMMEND:
When you create new branch, don't edit master branch until wouldn't merge it.

Conflict in remote repo

You clone/pull remote repository and modify it, at same time, someone (you) clone/pull it and modify it simultaneously (modified in GitHub). Another one (you) push new commits on remote repo and after that you push your commits. In this time, git get into the conflict.


Git show

Write about it.

git show [options]

Options:

  • <commit_key> : Put in git log
  • <desired_tag> :

Git checkout

Summery all checkout application in git.

git checkout [options]

Options:

  • <branch_name> : Switch from current branch to desired branch.
  • <file_name> : Ignore all alteration that has been done on file(s).
  • <tag_name> : Switch to desired tag.
  • '<commit_code>' : Switch to desired commit.

Undoing


Unstage File

Unstage file(s) already has been staged.

git reset

???

Write about this

git rm [options]

Options:

  • <file_name> : Delete specific file or files from git.

.gitignore

Write about this

Ignore alterations

Ignore all alteration that has been done on file(s).

git checkout <file_name>

RECOMENDED:
Utilize this command, when you're working on file, and you wouldn't reach to valuable commit and want to back to last commit.


Help in git

Write about this

git <command> -help

Connect with me: