Saturday, May 23, 2015

GIT Commands

Working with GIT Locally

Creates a new GIT repository

git init

Adding Files

echo “Hello” > README.txt
git status
git add README.txt

Adds all files including untracked ones

git add –A
git commit
git commit –m “Test Comment”
git commit –am “Add and Commit”

Add all modified files

git add -u
‘-u’ only adds updated files


Commit History

 git log
igt log origin/master
git log -oneline
git log –oneline | wc –l
Shows different branches and merges
git log –oneline --graph

Shows Authors and commit messages

git shortlog
git shortlog -s

Display the last commit

git show HEAD

Diff

git diff dd6819..a15ec6
git diff  HEAD~1..HEAD
git diff HEAD~1..

Remove Files

rm file1.txt
git add -u

Undoing Changes in Local copy

Get the default version of an updated file

git checkout README.txt

Revert several files (Reset the working back to the HEAD)

git reset --hard

Undoing Changes in the Repository

git reset –soft HEAD~1

Move the HEAD back. Delete the last commit and discard all the changes

git reset –hard HEAD~1

Clean the Working Copy

List the files to be cleaned

git clean –n

Clean the repository

git clean –f
 

GIT Ignore File (.gitignore)

You can specify files which you don’t want to commit such as log files.

Working with GIT Remotely

Cloning a Remote Repository

git clone https://github.com/apache/kafka.git

Shows the remote

git remote
git remote –v

Show Branches and Tags

git branch

Shows remote branches

git branch -r
git tag

Sync with remote Repository

Pull down any changes from remote repository

git fetch

Merge data from another branch to current working copy

git merge origin/master

Pull Request 

Performs both Fetch and Merge

 git pull origin master
git branch --set-upstream master origin/master

Push Changes to the Remote Repository

git push
git push --tags

Tags

Displays the Tag

git tag
git tag v1.0
git tag

GIT Branches

List Branches

git log --graph --oneline --all --decorate

Add command allies to Git config

git config --global allis.lga “log --graph --oneline --all --decorate”      
git lga

Creates a new Branch

git branch feature1
git checkout feature1

Rename a Branch

git branch –m fix1 bug1234

Delete a Branch

git branch -d bug1234

Force Delete

git branch -D bug1234

Create and Check out the a branch

git checkout -b feature2

Recovering Deleted commits

git reflog
git branch bug1234 5a78b

Hold Pending Changes

git stash
git stash list
git checkout bug1234
git stash apply

Apply and Delete Stash

git stash pop
git stash drop

No comments:

Post a Comment