Difference between revisions of "Git Tips"

From TedYunWiki
Jump to navigation Jump to search
 
(9 intermediate revisions by the same user not shown)
Line 50: Line 50:
 
To update the list of remote branches:
 
To update the list of remote branches:
 
  git remote update origin --prune
 
  git remote update origin --prune
 +
or
 +
git remote prune origin
  
 
To see diff between the current and the last version
 
To see diff between the current and the last version
Line 56: Line 58:
 
To see the list of contributors and the number of commits made by each pereson
 
To see the list of contributors and the number of commits made by each pereson
 
  git shortlog -s -n
 
  git shortlog -s -n
 +
 +
To clear the working directory, the following command will remove untracked files, including directories (-d). Replace the -f argument with -n to perform a dry-run or -i for interactive mode and it will tell you what will be removed. Add (-x) to remove files ignored by git.
 +
git clean -d -f
 +
 +
To disable vi dialog during merge, add "export GIT_MERGE_AUTOEDIT=no" to .bashrc in home directory. In older versions:
 +
git config --global core.mergeoptions --no-edit
 +
 +
To speed up git's autocomplete on Windows https://github.com/msysgit/msysgit/wiki/Diagnosing-why-Git-is-so-slow
 +
git config --global core.fscache true
 +
 +
Cleanup unnecessary files and optimize the local repository
 +
git gc
 +
 +
Store credentials for 24 hours when using https
 +
git config credential.helper 'cache --timeout=86400'

Latest revision as of 18:12, 14 November 2017

Cheatsheet

See state of commits of your local branch vs repository

git status

You are working on a new feature - newfeat

1) create a new branch, newfeat

git checkout -b newfeat master

2) make changes, etc in your branch

3) push feature branch into repository

git push -u origin newfeat

4) merge back into master

git checkout master
git merge --no-ff newfeat
git branch -d newfeat
git push origin master


If master changes and you want to incorporate master changes into your branch:

git rebase master

or

git merge master


Delete branch local:

git branch -d old_branch

remote:

git push origin :old_branch

Undo last commit,

1) reset files to before you committed

git reset --hard HEAD~1

2) just undo the "commit" action but leave everything else as is

git reset --hard HEAD~1

To see the list of remote branches:

git branch -a

or

git branch -r

To update the list of remote branches:

git remote update origin --prune

or

git remote prune origin

To see diff between the current and the last version

git diff HEAD^ HEAD

To see the list of contributors and the number of commits made by each pereson

git shortlog -s -n

To clear the working directory, the following command will remove untracked files, including directories (-d). Replace the -f argument with -n to perform a dry-run or -i for interactive mode and it will tell you what will be removed. Add (-x) to remove files ignored by git.

git clean -d -f

To disable vi dialog during merge, add "export GIT_MERGE_AUTOEDIT=no" to .bashrc in home directory. In older versions:

git config --global core.mergeoptions --no-edit

To speed up git's autocomplete on Windows https://github.com/msysgit/msysgit/wiki/Diagnosing-why-Git-is-so-slow

git config --global core.fscache true

Cleanup unnecessary files and optimize the local repository

git gc

Store credentials for 24 hours when using https

git config credential.helper 'cache --timeout=86400'