GIT Notes
GIT Notes
Install git
command is:
ON lab:
click on terminal
execute command:
$ sudo su -
$ git --version
$ mkdir myproject
$ cd myproject
$ touch index1.html index2.html
$ git init
created a local repo
$ cat ~/.gitconfig
$ git ls-files
Scenario 4: git log
$ git log
$ git log --oneline
**********
Scenario 5: Modify an exisitng file, which is already in Local repo
1 method:
2nd method:(using -a option: add all the changes & commit it)
************
********************************************************
Scenario6: Deletion of file
# git rm file1
# git status
# git commit -m "deletion of file1"
# ls
# git ls-files
# vim log
# git status // file untracked
# vim .gitignore // add name of file "log" , which wil be noe ignored
# git status // log will be ignored and .gitignore untracked
# git add .gitignore
# git commit -m "added ignore file"
# git status // working tress has to be clean
************************************************************
# git rm file3
# git commit -m "deleted file3"
# ls
# git ls-files
***************************************************************
Scenario 9: Resetting the commits OR Removing Certain changes
*******************************************************************
Branching
# git checkout b1
# git login // new file , add text ==> filename same but text is different
# git add login
# git commit -m "login file"
Merge b1 to master
# git checkout b1
# git merge master b1
# git chckout master
********************************************************
STASHING of files on GIT
# git status ==> chnages that are untracked and we don’t want to commit them right
now.
# git stash ==> all the untracked changes will be moved to temperory space
# git checkout b1
# vim logout.txt
==> add code for logout ==>esc ==> :wq!
#git add logout.txt
# git commit -m “logoutcode”
# git stash pop stash@{0} ==> will revert back all untracked file chnages
After unstashing, the files will be dropped from temperory shelves.
OR
# git stash apply statsh@{0} ==> will revert back chnages from temperory shelves
to working directory
// and files still remains on temperory shelves if needed latter in other branches.
# git statsh list ==> nothing will be there on executing stash pop.
PARTIAL STASH
# git stash -p ==> give y for which ever file we want to stash
# git log --oneline ==> see how many commits are there and reset commits to only
last 2 commits
# git log --oneline ==> three commit id will be there --copy it on notepad
# git checkout b2
# vim logout.txt ==> instert code for logout ==> esc ==> :wq!
# git add logout.txt
# git commit -m “logout on b2”
# git log --online ==> 3 commits will be there on branch b2 ==> copy it on notepad
Now if we use merge command, we will have commits and code as file1.txt, file2.txt,
logout and login.txt(from master) . which is called as parallel merge
# git log --oneline ==> we will have commits arranges in liner fashion. ==> copy on
notepad and show.
***********************************************************************************
*
REMOTE REPOSITORY:
Copy the URL of the repository to add local repo to external repo:
# git remote -v // will show that origin is mapped to external repo url
# git push origin b1 ==> pushes files of b1 branch onto external repo
It will ask for username and password ..give follwoing details:
Username:
Passowrd:
Now go to external repo and see all the files of b1 will be available.
************************************************************************
DELETE Branches in external REPOSITORY
- Delete branch on local repo:
# git branch
So we have to first pull chnages from external repo , add them , commit them and
then push our changes
# git pull origin
Cloning a repository
*************************************************
Go to github--> create a new repository
Use this repo:
https://github.com/Sonal0409/7AMGITDEMO
On host machine:
Create an emplty directory
# cd ..
# pwd
# mkdir project2
# cd project2
# git clone URL of new external repository
==> it will copy all the files from external to your local repository
# ls
# cd directoryname/
# ls ==> files will be shown
# ll -al ==> all files and .git file will also be there