×
Clear all filters including search bar
Valeri Tandilashvili's Personal Professional Blog
git remote -v
Add remote repository URL$ git remote add origin https://github.com/tandilashvili/testproject.git
Setting remote repository URLgit remote set-url origin https://github.com/tandilashvili/testrepo.git
cd /Users/Brad/Desktop/Sites
Instead of typing the full path we can drag the folder on top of our command line
pwd
also works on windows
git config --global user.name "John"
git config --global user.email "johndoe@gmail.com"
Check if we have set the Git username and email globallygit config --global user.name
git config --global user.email
Set username and email for a single repositorygit config user.name "John"
git config user.email "johndoe@gmail.com"
Check if we have set the Git username and email locally (for a single repository)git config user.name
git config user.email
git commit -m 'Initial commit'
Adds all the modified and deleted files to staging area and then saves changes to local repository with messagegit commit -a -m 'Initial commit' / git commit -am 'Initial commit'
Makes changes to the last commit, adds some files or edits commit messagegit commit --amend -m 'Initial commit'
git checkout -- .
Reverts some.txt
file changes from the last commit (to discard changes in working directory)git checkout -- some.txt
HEAD will be detached and pointed towards the commit (to go back to master git checkout master
should be run)git checkout b4ba3088679ff70b45df2aefc7c0a13d41a2bd76
Reverts all changes (from the specified commit)git checkout b4ba3088679ff70b45df2aefc7c0a13d41a2bd76 .
Reverts some.txt
file changes (from the specified commit)git checkout b4ba3088679ff70b45df2aefc7c0a13d41a2bd76 some.txt
To switch to an existing branchgit checkout another_branch
To switch to a new branchgit checkout -b new_branch
a.txt
fileecho 'some txt' > a.txt
Adds some text at the bottom of the filea.txt
file (with new line)echo 'some txt' >> a.txt
The file will be created, if does not exist
also works on windows
a.txt
filetouch a.txt
Creates several filestouch .gitignore a.txt b.txt
does not work on windows
git reset
defaults to HEAD
)git reset / git reset HEAD / git reset HEAD .
Removes the specified file from staginggit reset HEAD 1.txt
Deletes all commits after the specified commit but does not change source code (keeps files staged)git reset --soft i4ol54f
Deletes all commits after the specified commit but does not change source code (keeps files unstaged)git reset i4ol54f / git reset --mixed i4ol54f
Deletes all commits after the specified commit and moves HEAD to that commit (this will get rid of changes so we should be careful)git reset --hard 004caa3
Deletes the last 3 commitsgit reset --hard HEAD~3
git reset
defaults to --mixed
index.html
to staging areagit add index.html
Adds any html file
to staging areagit add *.html
Adds several files to staging areagit add index.html another.html index.php
Adds modified and deleted files onlygit add -u / git add --update
Adds modified and new files only (but not new files without names)git add *
Adds all the changes - modified, new and deleted files (-A
is a short handhand notation for --all
)git add . / git add --all / git add -A
Adds all files including files with no names (ignores deleted files)git add . --no-all / git add . --ignore-removal
If we want to commit only part of changes of the same file --patch
or -p
is usedgit add --patch / git add -p
Possible answers for the command:
y
stage this hunk for the next commit
n
do not stage this hunk for the next commit
q
quit; do not stage this hunk or any of the remaining hunks
a
stage this hunk and all later hunks in the file
d
do not stage this hunk or any of the later hunks in the file
...
The complete list of the possible answers is on the link of the note