Guangning Yu's Blog
Home
Code
Data
Setup
Industry
MachineLearning
Archive
Git Basics
2019-02-17 01:40:29
|
git
- Setting user name and email ```bash git config --global user.name "Guangning Yu" git config --global user.email "hi@guangningyu.com" ``` - Showing remotes ```bash git remote -v ``` - Changing a remote’s URL ```bash git remote set-url origin git@github.com:guangningyu flasky.git ``` - Pulling from remotes ```bash git pull origin master ``` - Pushing to remotes ```bash git push origin master ``` - Commit using default message ```bash git commit —no-edit ``` - Cancel last commit ```bash git reset HEAD~ ``` - Undo a git add ```bash git reset filename.txt ``` - Define author & committer ```bash GIT_COMMITTER_NAME='Jane Doe' GIT_COMMITTER_EMAIL='jane@doe.com' git commit —author="John Doe <john@doe.com>" -m "This is authored by John Doe and committed by Jane Doe." ``` - Undo git rm ```bash git checkout HEAD path/to/file ``` - Check out a remote branch ```bash git branch -a git checkout test_branch ``` - Create a new branch ```bash git checkout -b [name_of_your_new_branch] ``` - Push a local branch to remote ```bash git push -u origin [name_of_your_local_branch] ``` - Delete a local branch ```bash git branch -d [branch_name] ``` - Remove untracked files ```bash git clean -fd ``` - Discard unstaged changes ```bash git checkout — . ``` - Force full remote branch ```bash git reset —hard origin/master ``` - Merge master branch into feature branch ```bash git checkout feature1 git merge master ``` - Delete git history ([reference](https://stackoverflow.com/questions/9683279/make-the-current-commit-the-only-initial-commit-in-a-git-repository/13102849#13102849)) ``` git clone git@bitbucket.org:oliverwymantechssg/c19-credit-analytics-tool.git git checkout --orphan new-branch git add -A git commit -m "release 1.0" git branch -D master git branch -m master git gc --aggressive --prune=all ``` - Change editor ``` git config --global core.editor vim ``` - Unstage deleted files ``` git reset -- . git checkout -- . ``` - Delete a remote tag ``` git push --delete origin YOUR_TAG_NAME ``` - Add a tag ``` git tag <tag_name> ``` - Push tags to remote ``` git push origin ZAW-1.0.0 ``` or ``` git push --tags ```
Previous:
Bash Basics
Next:
Javascript Basics