GIT Basic Commands

From Logic Wiki
Jump to: navigation, search

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'