Thursday, September 21, 2017

Git Study -1

Git Configuration

git config --global user.name <name>
Set the user name to be used for all actions.
git config --global user.email <email>
Set the email to be used for all the
actions.
git config --global alias.<alias-name><git-command>
Create a shortcut for the git command
git config --system core.editor <editor>  
Set text editor for all the command actions
git config --global --edit
Open global configuration file in text editor for manual editing
git config --global color.ui auto
Enable helpful colourization of command line outputs
Setting Up a Git Repo

git init  
Initialize an empty git repo in current project
git clone (Repo URL)
Clone the repository from github to the project folder
git clone (Repo URL) (Folder )
Clone the repository into the specific folder
git remote add origin
https://github.com/username/(repo_name)
.git
Create a remote repo pointing on your GitHub
repository which you already created there.
git remote
Show the name of remote repositories
git remote -v
Show the name and URL’s of the remote repositories
git remote rm (remote repo name)
Remove the remote repository
git remote set-url origin (git URL)
Change the URL of the Repository
git fetch
Get the latest changes from the origin but not merge
git pull
Get the latest changes from the origin and merged them
Local File Changes

git add (file name)
Add the current changes of file to staging
git add (.dot)
Add the whole directory changes to staging(no delete files)
git add -A
Add all new, modified and deleted files to staging
git rm (file_name)
Remove the file and untrack it.
git rm (file_name)
Remove the file and untrack it.
git rm --cached (file_name)
Untrack the current file
git mv (file_name) (new_file_name)
Changes the filename and prepare to commit
git checkout <deleted file name>
Recover the deleted file and prepare for commit
git status
Shows the status of files modified
git ls-files --other --ignored
--exclude-standard
Shows the list of all ignored files
git diff
Show unstaged changes in index and working
directory
git diff --staged
Shows file differences between staging and the last file
version
git diff (file_name)
Show changes in single file compared to last commit
Declare Commits

git commit -m “(message)”
Commit the changes with a message
git commit -am “(message)”
Add all changes to staging and commit them with
message
git checkout <commit hash>
Switch to the provided commit
git show <commit hash>
Outputs metadata and content changes of the specified
commit
git reset <commit hash>
Undo all commits after this commit. Preserving changes
locally
git reset --hard <commit hash>
Discard all history and changes back to the given
Commit
git reset --hard Head
Discard all local changes in working directory
git log
Show history of changes
git log -p
Shows the full display of each commit
git log -oneline
Shows the list of commits with only message
git log --follow (file_name)
List all the history for the current file
git blame (file_name)
Shows all changes with name of user
git stash
Temporarily saves all modified tracked files
git stash pop
Restores the most recently stashed files
git stash list
List all stash changedsets
git stash apply
Apply the latest stashed contents
git stash drop
Discard the most recently stashed files
git stash apply (stash id)
Re-Apply a specific stash content by ID
git stash drop (stash_id)
Drop a specific stash content by ID
git push
Push changes to the Origin
git push origin (branch_name)
Push branch to the Origin
Git push -f origin (branch_name)
Force push the changes to the origin
git tag (tag_name)
Define tag for a version
git diff <commit>^ <commit>
git diff COMMIT~ COMMIT
git diff 15dc8^ 15dc8
will show you the difference between that COMMIT's ancestor and the COMMIT
ie. difference between parent of commit (15dc8^) and commit (15dc8).
Branching

git branch
Shows the list of all branches
git branch <branch_name>
Create a new branch
git branch -a
List all branches local and remote
git branch -m <old_name> <new_name>
Rename the branch
git checkout -b <branch_name>
Create a branch and switch to it
git checkout <branch_name>
Checkout to the branch
git checkout -b <new_branch_name> origin/<branch_name>
Get a remote branch from origin to the local
directory
git branch -d <branch_name>
Delete a specified branch
git merge <branch_name>
Merge the current branch into master(first
checkout to master)
git rebase <branch_name>
Take all the changes of the branch and restate on
other.
git rebase <base>
Rebase the current branch onto base. Base can
be a commit ID or branch name.
git fetch remote <branch_name>
Fetches the specific branch from the repository
git diff <branch_name>..<branch_name>
Shows the differences of two branches
git pull --rebase
Fetch the remote’s copy of current branch and
rebases it into the local copy
git push --all
Push all of your local branches to the specified
remote

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More