Working with GIT Locally
Creates a new GIT repository
git initAdding Files
echo “Hello” > README.txtgit status
git add README.txt
Adds all files including untracked ones
git add –Agit 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 logigt 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 shortloggit shortlog -s
Display the last commit
git show HEADDiff
git diff dd6819..a15ec6git diff HEAD~1..HEAD
git diff HEAD~1..
Remove Files
rm file1.txtgit add -u
Undoing Changes in Local copy
Get the default version of an updated file
git checkout README.txtRevert several files (Reset the working back to the HEAD)
git reset --hardUndoing Changes in the Repository
git reset –soft HEAD~1Move the HEAD back. Delete the last commit and discard all the changes
git reset –hard HEAD~1Clean the Working Copy
List the files to be cleaned
git clean –nClean the repository
git clean –fGIT 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.gitShows the remote
git remotegit remote –v
Show Branches and Tags
git branchShows remote branches
git branch -rgit tag
Sync with remote Repository
Pull down any changes from remote repository
git fetchMerge data from another branch to current working copy
git merge origin/masterPull Request
Performs both Fetch and Merge
git pull origin mastergit branch --set-upstream master origin/master
Push Changes to the Remote Repository
git pushgit push --tags
Tags
Displays the Tag
git taggit tag v1.0
git tag
GIT Branches
List Branches
git log --graph --oneline --all --decorateAdd command allies to Git config
git config --global allis.lga “log --graph --oneline --all --decorate”git lga
Creates a new Branch
git branch feature1git checkout feature1
Rename a Branch
git branch –m fix1 bug1234Delete a Branch
git branch -d bug1234Force Delete
git branch -D bug1234Create and Check out the a branch
git checkout -b feature2Recovering Deleted commits
git refloggit branch bug1234 5a78b
Hold Pending Changes
git stashgit stash list
git checkout bug1234
git stash apply
Apply and Delete Stash
git stash popgit stash drop
No comments:
Post a Comment