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 theactions. 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 originhttps://github.com/username/(repo_name).git Create a remote repo pointing on your GitHubrepository 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 workingdirectory git diff --staged Shows file differences between staging and the last fileversion 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 withmessage git checkout <commit hash> Switch to the provided commit git show <commit hash> Outputs metadata and content changes of the specifiedcommit git reset <commit hash> Undo all commits after this commit. Preserving changeslocally git reset --hard <commit hash> Discard all history and changes back to the givenCommit 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 thatCOMMIT
's ancestor and theCOMMIT
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 localdirectory git branch -d <branch_name> Delete a specified branch git merge <branch_name> Merge the current branch into master(firstcheckout to master) git rebase <branch_name> Take all the changes of the branch and restate onother. git rebase <base> Rebase the current branch onto base. Base canbe 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 andrebases it into the local copy git push --all Push all of your local branches to the specifiedremote
0 comments:
Post a Comment