GIT Basic Commands
From Logic Wiki
Contents
- 1 Basics
- 2 Removing files from being tracked
- 3 Removing deleted files
- 4 Reverting added files
- 5 Reverting everything to last commit
- 6 Go Back to previous commit
- 7 Branch
- 8 Copy file from another branch
- 9 Remote
- 10 Merge
- 11 Conflicts
- 12 Delete Branch
- 13 To see the last commit on each branch
- 14 To list branches
- 15 To delete a branch
- 16 Using MELD with GIT on Windows
Basics
git status git add . git commit -m "test" git push origin master
Removing files from being tracked
git rm --cached <FilePath>
Removing deleted files
git add -u
Reverting added files
git reset
Reverting everything to last commit
git checkout .
Go Back to previous commit
git checkout .
Branch
To create a branch and switch to it
git checkout -b BranchName
git checkout master git checkout BranchName
Copy file from another branch
git checkout otherbranch myfile.txt
Remote
git remote add origin https://github.com/user/repo.git git remote remove origin
Merge
git push origin Ticket24 git checkout master git merge Ticket24
Conflicts
git diff HEAD git diff --staged
git mergetool git commit git push origin master
Delete Branch
git branch -d Ticket24
To see the last commit on each branch
git branch -v
To list branches
git branch -r :remotes git branch -a :all
To delete a branch
git branch -d Ticket24 -d merged -D not merged git push origin :Ticket24 :deletes remote branch
Using MELD with GIT on Windows
PATH=$PATH:'/C:/Program Files (x86)/Meld/python'
git config --global mergetool.meld.path 'C:\Program Files (x86)\Meld\meld'
$ git config --global mergetool.meld.path 'C:/Program Files (x86)/Meld/meld/meld.exe'