Friday, 22 May 2020

Basic Git Commands


 Task Command
 Lists all branches git branch -a 
 Lists remote branches git branch -r
 Lists local branches git branch -l OR git branch
 Delete local branch git branch -D fix/authentication
 Delete remote branch git branch origin --delete fix/authentication


Mysterious vanishing branches in git
1) You can use git reflog and find the commit of your files
2) Then you can run this to recreate the branch:
     git checkout <commit-id> -b <new-branch-name>

..................................................
git --version
git config --global user.name "John Smith"
git config --list

command to Initilize folder as GIT repo -> git init
[This will be master branch]

current status of folder-> git status
[to check which files are not commited]

add all files in current directory to git -> git add .

commit the current state of folder to git repo -> git commit
OR
git commit -m "First commit"

small Log of all commits -> git log --oneline
check full details of log -> git log

checkout previous commited file->   git checkout <commit> <file>

To reset changes->   git reset HEAD <file>
[reset staging are to last commit without disturbing working dir]

Restore change to last commit -> git checkout -- <file>

Add local git repo to remote repo and then can be commited in remote repo
git remote add origin <url>
Then Push local git repo to origin to master branch
git push -u origin master

git clone <url>

.gitignore file contains entry of files/folders[temporary] that should be ignored during commit

No comments:

Post a Comment