Tuesday, 29 September 2015

GIT COMMANDS REFERENCE




A list of some basic Git commands that will get you going with Git.


Git task
Notes
Git commands
Telling Git who you are
Make sure you configure the author name and email address to be used with your commits.
Take Note that Git strips some characters (for example trailing periods) from user.name.
git config --global user.name "Ian Smonerl"
git config --global user.email ian@example.com
Creating a new local repository

git init
Checking out a repository
Create a working copy of the local repository:
git clone / path/to/repository
For a remote server, just use:
git clone username@host:/path/to/repository
Adding files
Adding one or a couple of files to staging (index):
git add <filename>

git add *
Committing
Commit changes to head :
git commit -m "The Commit message"
Committing any files that you've added with git add, and also commit any files you've changed since then:
git commit -a
Push
Send the changes to the master branch of your remote repository:
git push origin master
Status
Listing the files you have changed and those you still need to commit or add.
git status
Connecting to a remote repository
If you have not connected your local repository to the remote server, add the server so as to be able to push to it:
git remote add origin <server>
List all the currently configured remote repositories:
git remote -v
Branches
Creating a new branch and switch to it:
git checkout -b <branchname>
Switch from one branch to another:
git checkout <branchname>
Listing all the branches in your repository, and also tell you what branch you are currently in:
git branch
Deleting the feature branch:
git branch -d <branchname>
Pushing the branch to the remote repository, so other people can use it:
git push origin <branchname>
Pushing all branches to your remote repository:
git push --all origin
Deleting a branch on your remote repository:
git push origin :<branchname>
Update from your remote repository
Fetching and merging changes on the remote server to your working directory:
git pull
To merge different branches into your active branch:
git merge <branchname>
Viewing all the merge conflicts:
Viewing the conflicts against the base file:
Previewing changes, before merging:
git diff
git diff --base <filename>
git diff <sourcebranch> <targetbranch>
After you have manually resolved any kind of conflicts, you mark the changed file:
git add <filename>
Tags
You can use tagging to mark a significant changeset, e.g a release:
git tag 1.0.0 <commitID>
Commit Id is the leading characters of the changeset ID, up to 10, but they must be unique. Get the ID using:
git log
Pushing all tags to remote repository:
git push --tags origin
Undoing local changes
In case you end up messing up, you can replace the changes in your work tree with the last content in head:
Changes already added to the indexing, as well as new files, that will be kept.
git checkout -- <filename>
Instead, so as to drop all your local changes and commits, fetching the latest history from the server and point your local master branch at it, do this:
git fetch origin

git reset --hard origin/master
Search
Searching the working directory for foo():
git grep "foo()"

To Know more About This Content Git Command Reference Visit us..

No comments:

Post a Comment