git config --global user.name "John Doe"
git config --global user.email "[email protected]"
Use --global
to set the configuration for all projects. If git config
is used without --global
and run inside a project directory, the settings are set for the specific project.
cd project/
git config core.filemode false
This option is useful if the file permissions are not important to us, for example when we are on Windows.
git config --list
cd existing-project/
git init
git clone https://github.com/user/repository.git
This creates a new directory with the name of the repository.
git clone https://github.com/user/repository.git .
git help clone
cd repository/
git pull origin master
Where origin is the remote repository, and master the remote branch.
If you don't want to merge your changes, use git fetch
git remote -v
git remote set-url origin http//github.com/repo.git
git remote add remote-name https://github.com/user/repo.git
git diff
Note that this does not track new files.
git diff --cached
git diff origin/master
Note that origin/master
is one local branch, a shorthand for refs/remotes/origin/master
, which is the full name of the remote-tracking branch.
git diff develop origin/develop
git diff develop..origin/develop resources/lang/
git diff COMMIT1_ID COMMIT2_ID
git diff --name-only COMMIT1_ID COMMIT2_ID
git diff-tree --no-commit-id --name-only -r COMMIT_ID
or
git show --pretty="format:" --name-only COMMIT_ID
source: http://stackoverflow.com/a/424142/1391963
git diff --cached origin/master
git show COMMIT_ID
git status
git add changed_file.txt
git add folder-with-changed-files/
git commit -m "Commiting changes"
git rm removeme.txt tmp/crap.txt
git mv file_oldname.txt file_newname.txt
git commit -m "deleting 2 files, renaming 1"
git commit --amend -m "New commit message"
git push origin master
git log
git log -2
git log -p -2
git log --pretty=oneline
git revert dd61ab21
git push origin master
# reset the index to the desired tree
git reset 56e05fced
# move the branch pointer back to the previous HEAD
git reset --soft HEAD@{1}
git commit -m "Revert to 56e05fced"
# Update working copy to reflect the new commit
git reset --hard
Source: http://stackoverflow.com/q/1895059/1391963
git reset --soft HEAD~1
git reset --hard HEAD~1
git reset --mixed HEAD~1
Or git reset HEAD~1
See also http://stackoverflow.com/q/927358/1391963
git reset origin/master
git fetch origin
git reset --hard origin/master
git branch
git branch -a
git diff > patch-issue-1.patch
git add newfile
git diff --staged > patch-issue-2.patch
git add newfile
git diff HEAD > patch-issue-2.patch
git format-patch COMMIT_ID
git format-patch HEAD~2
git format-patch origin/master
git format-patch --binary --full-index origin/master
git apply -v patch-name.patch
git am patch1.patch
git tag 7.x-1.3
git push origin 7.x-1.3
git checkout master
git branch new-branch-name
Here master
is the starting point for the new branch. Note that with these 2 commands we don't move to the new branch, as we are still in master and we would need to run git checkout new-branch-name
. The same can be achieved using one single command: git checkout -b new-branch-name
git checkout new-branch-name
git cherry -v master
(master
is the branch you want to compare)
git checkout master
git merge branch-name
Here we are merging all commits of branch-name
to master
.
git merge branch-name --no-commit --no-ff
git diff branch-name
git diff branch-name path/to/file
git branch -d new-branch-name
git push origin new-branch-name
git fetch origin
git rev-parse --show-toplevel
Source: http://stackoverflow.com/q/957928/1391963
git rm $(git ls-files --deleted)
Source: http://stackoverflow.com/a/5147119/1391963
git clean -f
Including directories:
git clean -f -d
Preventing sudden cardiac arrest:
git clean -n -f -d
Source: http://stackoverflow.com/q/61212/1391963
Short answer: Git does not do that.
Long answer: See http://stackoverflow.com/a/10847242/1391963
git reset HEAD file.txt
git describe --tags `git rev-list --tags --max-count=1`
Source. See also git-describe.
screen
for((i=1;i<=10000;i+=1)); do sleep 30 && git pull; done
Use Ctrl+a Ctrl+d to detach the screen.
history | grep git
or
grep '^git' /root/.bash_history
git for-each-ref --sort=-committerdate refs/heads/ | head
Source: http://stackoverflow.com/q/5188320/1391963
cd ..
tar cJf project.tar.xz project/ --exclude-vcs
git diff --name-only | xargs tar -cf project.tar -T -
grep -H -r "<<<" *
grep -H -r ">>>" *
grep -H -r '^=======/pre> *
There's also git-grep.
patch < file.patch
$ git commit -m "Something terribly misguided" (1)
$ git reset HEAD~ (2)
<< edit files as necessary >> (3)
$ git add ... (4)
$ git commit -c ORIG_HEAD (5)
- This is what you want to undo
- This leaves your working tree (the state of your files on disk) unchanged but undoes the commit and leaves the changes you committed unstaged (so they'll appear as "Changes not staged for commit" in git status and you'll need to add them again before committing). If you only want to add more changes to the previous commit, or change the commit message1, you could use git reset --soft HEAD~ instead, which is like git reset HEAD~ but leaves your existing changes staged.
- Make corrections to working tree files.
- git add anything that you want to include in your new commit.
- Commit the changes, reusing the old commit message. reset copied the old head to .git/ORIG_HEAD; commit with -c ORIG_HEAD will open an editor, which initially contains the log message from the old commit and allows you to edit it. If you do not need to edit the message, you could use the -C option.