Most useful git commands





Introduction

Git is maybe the best control version software. At present, Git has been the most used in managing source codes  and responsible for everything happens locally on your computer. Therefore, I bring to you this post showing the most useful commands to make your work more easier. Enjoy it and share with other developers.

Check the status of the current branch, list the files changed and need to add or commit:

git status

List all the branches, and also tell you what branch your're currently in: 

git branch

See diff of what is changed but not added:

git diff

See diff of what is staged but not yet committed:

git diff --cached

See recent commit history:

git log

See commit history for the last two commits:

git log -2

See commit history for the last two commits, with diff:

git log -p -2

See commit history printed in single lines:

git log --pretty=oneline

See differences between two commits:

git diff commit1_id commit2_id

See the files changed between two commits:

git diff --name-only commit1_id commit2_id

See diff before push:

git diff --cached origin/master

See details of your change of a commit:

git show commit_id

Make some changes, commit them

git add changed_file.txt
git commit -m "Commiting changes"

Rename, move and remove files:

git rm remove_file.txt tmp/crap.txt
git mv old_name.txt new_name.txt
git commit -m "remove and move some files"

Change message of last commit:

git commit --amend -m "New commit message"

Push local commits to remote branch:

git push origin branch name

See recent commit history

git log

See commit history for the last two commits

git log -2

See commit history for the last two commits, with diff

git log -p -2

See commit history printed in single lines

git log --pretty=oneline

Undo last commit, preserving local changes

git reset --soft HEAD~1

Reset to remote state

git fetch origin
git reset --hard origin/master

Create a branch

git checkout master
git branch branch_name

Checkout a branch

git checkout branch_name

See commit history for just the current branch

git cherry -v master
(master is the branch you want to compare)

Merge branch commits

git checkout master
git merge branch-name

See differences between the current state and a branch

git diff branch_name

See differences in a file, between the current state and a branch

git diff branch_name path/to/file

Delete a branch

git branch -d branch_name

If you liked this article

Let's subscribe the updates of Scuti!
Share on Google Plus

About Quang Hoan

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 Comments:

Post a Comment