DEV Community

Carlos A. Martinez
Carlos A. Martinez

Posted on

Git for Beginners

drawing


Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. :-)

Image description

Setting git 🙂

Command Description
git --version Git version.
git config --global user.email ['email'] Setting email.
git config --global user.name ['name'] Setting name.
git config -l Show detail of git settings.
git config --global color.ui true Setting color on git.

Git Commands 🙃

Command Description
git init Init to repository.
git status shows the state of the working directory and the staging area.
git add Add files to the staging areay 'Tracked'.
git add . Add all files to the staging areay.
git commit -m ['message'] Commit files to the local repository.
git commit -am ['message'] Add and commit files to the local repository.
git show Shows one or more objects (blobs, trees, tags and commits).
git log Lists the commits made in that repository.
git log ['file'] Show commits made in that file specified.
git log --stat Show commits made in that file specified.
git rm ['folder/file'] Removes a file from both the repository and the working directory.
git rm --cache ['folder/file'] Remove files from staging area.
git clone ['URL'] Used to target an existing repository and create a clone.
git diff ['sha'] Show changes between commits and staging.
git diff ['sha'] ['sha'] Show changes between commits.
git checkout ['branch-name'] Switch branches.
git checkout ['sha'] Switch restore working tree files.
git checkout -b ['branch-name'] Reate and switch branches.
git tag ['tag-name'] Tags are ref's that point to specific points in Git history.
git tag -a v1.4 -m ['version1.4'] Command will create a new annotated tag identified with v1.4.

Git-branch - List, create, or delete branches 🙂

Command Description
git branch ['branch-name'] Create branch.
git branch -l List branches.
git branch -d ['branch-name'] Delete branch.
git branch -D ['branch-name'] Forza delete branch.
git checkout ['branch-name'] Git-checkout - Switch branches or restore working tree files.
git checkout ['SHA'] Git-checkout - Switch commit.
git checkout -b ['branch-name'] Create and switch branches.

Git Tags 🙂

Command Description
git tag ['tag-name'] Create tag.
git tag -l List tages.
git tag -d ['tag-name'] Delete tag.
git tag -D ['tag-name'] Forza delete tag.
git checkout ['tag-name'] Git-checkout - Switch tages or restore working tree files.
git checkout ['SHA'] Git-checkout - Switch commit.
git checkout -b ['tag-name'] Create and switch tages.

💻

$ git tag v0.1.0 // create tag

$ git tag -a v0.1.1 // creat tag with comment

$ git tag // list of tags
v0.1.0

$ git tag -l // list of tags
v0.1.0

$ git tag -l "0.1.*" // filter tags
v0.1.0

$ git tag -d v0.1.0 // delete tag
Delete tag 'v0.1.0' (was 1234234u)

$ git show v0.1.0 // show tags
Enter fullscreen mode Exit fullscreen mode

Git Cherry pick 🙂

Command Description
git cherry-pick ['SHA'] Pick commit

Git rebase 🙂

Command Description
git rebase -i --interactive HEAD~#commits rebase commits
git rebase -i --interactive HEAD~#commits rebase commits
git push --force force push
$ git rebase -i HEAD~2

pick 9309bf8 Autor: [Carlos Andres Martinez]
s 2438f88 Autor: [Carlos Andres Martinez]

# Rebase ea86eb8..2438f88 onto ea86eb8 (2 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# .       create a merge commit using the original merge commit's
# .       message (or the oneline, if no original merge commit was
# .       specified). Use -c <commit> to reword the commit message.
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

$ git push --force
Enter fullscreen mode Exit fullscreen mode

Git log 🙂

Command Description
git log show logs
git log ['file-name'] show logs
git log --oneline show logs a single line
git log --oneline --decorate show logs a single line

Export commits txt 🙂

git log > commits.txt

git blame ['file-name']

git reflog

thank you for reading

Top comments (5)

Collapse
 
tracygjg profile image
Tracy Gilmore

Hi Carlos,
I have found the following resources helpful in the past.

Regards, Tracy

Collapse
 
c4rlosc7 profile image
Carlos A. Martinez

Thanks for taking the time to read the post and the contribution. I loved the web gitexplorer.com/

Collapse
 
ernst_zero profile image
Ernst03

Well, first to comment.

I am just exploring Git.
I think it's never to late to learn to do better.
So thank you for posting this.

Collapse
 
c4rlosc7 profile image
Carlos A. Martinez

Thanks for taking the time to read the post. I recommend you practice. When you can look at this website gitexplorer.com/ greetings

Collapse
 
ernst_zero profile image
Ernst03

What is that saying? "Old Dog new Tricks."
I am taking the change slowly. Also it's my retirement activities so it will be.

Thinking of Community College class too. Just to be on the trajectory.
That is all I need.
So yeah, thanks for the link.
Hopefully this weekend will find me doing the Git and Github just fine.