DEV Community

Şammas Çölkesen
Şammas Çölkesen

Posted on • Updated on

Git Tuturial For Beginners

Git Tutorial


User Settings

for usage manuel

#git help
Enter fullscreen mode Exit fullscreen mode

config our username and email

#git config --global user.name "sammas"
#git config --global user.email "sammas@gmail.com"
Enter fullscreen mode Exit fullscreen mode

show everything configs

#git config --list
Enter fullscreen mode Exit fullscreen mode

Create

create repo

#cd path_folder 
#git init 
Enter fullscreen mode Exit fullscreen mode

clone a repo

#git clone repo_url
Enter fullscreen mode Exit fullscreen mode

Local Changes

view working status

#git status
Enter fullscreen mode Exit fullscreen mode

track changed files

#git diff
Enter fullscreen mode Exit fullscreen mode

add a file to next commit

#git add -p <filename>
Enter fullscreen mode Exit fullscreen mode

commit all files

#git add .
this means take snapshots of all things and maybe you later fuck things up and takes it back.
Enter fullscreen mode Exit fullscreen mode

commit message

#git commits -m "this is commit message"
Enter fullscreen mode Exit fullscreen mode

change the last commit

#git commit --amend
dont do it to pushed commits
Enter fullscreen mode Exit fullscreen mode

Search for commits that include a keyword

#git log -S"config.menu_items"
Enter fullscreen mode Exit fullscreen mode

Local History

view logs

#git log
#git log --author="sammas"
#git log -p file
Enter fullscreen mode Exit fullscreen mode

show stats

#git log --stat
Enter fullscreen mode Exit fullscreen mode

Print out visualization of your log

#git log --pretty=oneline --graph --decorate --all
Enter fullscreen mode Exit fullscreen mode

look at who and what changed in file

#git blame file
Enter fullscreen mode Exit fullscreen mode

show pathces

#git log -p
Enter fullscreen mode Exit fullscreen mode

Branches

list branches

#git branch -av
Enter fullscreen mode Exit fullscreen mode

switch HEAD branch

#git checkout <branch>
Enter fullscreen mode Exit fullscreen mode

create a new branch based on your current HEAD

#git branch <newBranch>
Enter fullscreen mode Exit fullscreen mode

delete local branch

#git branch -d <branch>
Enter fullscreen mode Exit fullscreen mode

mark the commit

#git tag <tagName>
Enter fullscreen mode Exit fullscreen mode

create branch from remote branch

#git checkout --track <remoteBranch>
Enter fullscreen mode Exit fullscreen mode

Publish

Pushing to a GitHub Repository

#git remote add project_name https://github.com/user/repo.git 
#git push -u project_name branch(master vs)
Enter fullscreen mode Exit fullscreen mode

Commit Directly to the Repository

#git commit -am "message"
Enter fullscreen mode Exit fullscreen mode

list all configured remotes

#git remote -v
Enter fullscreen mode Exit fullscreen mode

show info about remote

#git remote show <remotename>
Enter fullscreen mode Exit fullscreen mode

download all changes from remote but dont integrate into HEAD

#git fetch <remote>
Enter fullscreen mode Exit fullscreen mode

download all changes from remote and merge to HEAD

#git pull <remote> <branch>
Enter fullscreen mode Exit fullscreen mode

publish your tags

#git push --tags
Enter fullscreen mode Exit fullscreen mode

Merge

merge branch into your current HEAD

#git merge <branch>
Enter fullscreen mode Exit fullscreen mode

rebase your current HEAD onto branch

#git rebase <branch>
Enter fullscreen mode Exit fullscreen mode

abort rebase

#git  rebase --abort
Enter fullscreen mode Exit fullscreen mode

Undo

delet all local changes

#git reset --hard HEAD
Enter fullscreen mode Exit fullscreen mode

delete one file changes

#git checkout HEAD <file>
Enter fullscreen mode Exit fullscreen mode

reset your HEAD to previous commit

#git reset --hard <commit>

preserve all changes as unstaged changes
#git reset <commit>

and preserve uncommitted local changes
#git reset --keep <commit>
Enter fullscreen mode Exit fullscreen mode

delete files

#git rm file
Enter fullscreen mode Exit fullscreen mode

rename files

#git mv msg.txt mesaj.txt
Enter fullscreen mode Exit fullscreen mode

moving files

#git mv msg.txt home\sammas\msg.txt
Enter fullscreen mode Exit fullscreen mode

Getting Old Versions from the Repository

#git log
#git checkout 0128dba..... -- index.html
Enter fullscreen mode Exit fullscreen mode

Create Alias

alias gitA="git add -A ."
alias gitC="git commit -m"
alias gitP="git push"
Enter fullscreen mode Exit fullscreen mode

List all git aliases

#git config -l | grep alias | sed 's/^alias\.//g'
Enter fullscreen mode Exit fullscreen mode

Git Notes

Add or inspect object notes

list notes about object

git notes [list [<object>]]
Enter fullscreen mode Exit fullscreen mode

Add notes for a given object (defaults to HEAD)

git notes add [-f] [--allow-empty] [-F <file> | -m <msg> | (-c | -C) <object>] [<object>]
Enter fullscreen mode Exit fullscreen mode

Copy the notes for the first object onto the second object.

git notes copy [-f] ( --stdin | <from-object> <to-object> )
Enter fullscreen mode Exit fullscreen mode

Append to the notes of an existing object (defaults to HEAD). Creates a new notes object if needed.

git notes append [--allow-empty] [-F <file> | -m <msg> | (-c | -C) <object>] [<object>]
Enter fullscreen mode Exit fullscreen mode

Edit the notes for a given object (defaults to HEAD).

git notes edit [--allow-empty] [<object>]
Enter fullscreen mode Exit fullscreen mode

Show the notes for a given object (defaults to HEAD).

git notes show [<object>]
Enter fullscreen mode Exit fullscreen mode

Merge the given notes ref into the current notes ref

git notes merge [-v | -q] [-s <strategy> ] <notes-ref>
Enter fullscreen mode Exit fullscreen mode

Remove the notes for given objects (defaults to HEAD)

git notes remove [--ignore-missing] [--stdin] [<object>…​]
Enter fullscreen mode Exit fullscreen mode

Remove all notes for non-existing/unreachable objects.

git notes prune [-n] [-v]
Enter fullscreen mode Exit fullscreen mode

Print the current notes ref.

git notes get-ref
Enter fullscreen mode Exit fullscreen mode

Top comments (3)

Collapse
 
fennecdjay profile image
Jérémie Astor

That's a great cheatsheet, but I have to confess I expected something about note in git, as there is a

git notes

command I'd love to understand and use.

Collapse
 
kavanozkafa profile image
Şammas Çölkesen

hi, Jérémie
Thanks for advice. I've just add "git notes" section. Also I changed the name of article. No confusion anymore.

Collapse
 
fennecdjay profile image
Jérémie Astor

neat! 😄