Git Github
scenario A and B working in 1 company A in India B in Singapore different timezone there. so
install git on 2 machine A and B
yum install git
git config --global user.name "ajay"
git config --global user.email "ajayyadav19@gmail.com"
git config --list
which git
git --version
create git account on website
https://github.com
go to 1 machine
create direcotry
mkdir mumgit
cd mumgit
git init
create file
cat > mumbai1
git status check status, check if code in working space or commited
git add . add to staging
git commit -m "My First commit from mumbai" commited, changed got saved, and versioning started
git status now working are is empty
git it will show commit id
git show 8512df9c8bd it will show committed id status
connect system git to github
git remote add origin https://github.com/manjeetyadav19/repo.git
git push origin master push code to github
in another machine add remote origin and then pull data
git pull origin master pull data from repo
To ignore the file while committing
vi .gitignore
*.css
*.java
git add .gitignore
git commit -m "latest update exclude .css"
To check branches
git branch to check branches
git branch man to create branch
git checkout man to switch branch
git log --oneline will get all commits in one liner
To can't merge branch of diff repositories
We use pulling mechanism to merge branches
git merge man to merge branch
Stashing
git stash to put data in stash
git stash list to see stashed items list
git stash apply stash@{3}
then you can add and commit
To clear the stash items
git stash clear clear all stash file
Git reset
to reset staging area
git reset <filname> reset only one file
git reset. reset all file in staging area, remove all file from staging area
git reset --hard it will remove the code/file from the workspace and staging both area.
git revert
git revert help you to undo existing commit
git revert <command-id>
how to delete untracked files
git clear -n dry run
git clear -f delete forcefully
Tags
git tag -a <tagname> -m <msg> <commit-ID>
To see
git tag
To see particular commit content by using tag
git show <tag name>
To delete a tag
git tag -d <tagname>
cloning
git clone https://github.com/manjeetyadav19/repo.git cloning from github to local system
Question & Answers
how to remove git commit?
git log check commit
git reset --hard 3432dsfdsf
how to remove git commit from git repository also?
git push origin +master
what is difference b/w git fetch and pull?
git pull -git pull - fetch and merge both.
git fetch -git fetch but when you see changes, you will not see changes, so for changes, need to merge 1st.
git merge - to merge the code with branch
how to role back from commit?
in case if you just commited, or did not push to repository, you can do amend.
git commit --am
how to change your branch name?
git co -b chat1
git br -m chat1 chat
how to clean UN-traced file in git?
git clean -n it will show the file that can clean
git clean -f if you really want to delete unwanted files
if you committed 3-4 file in master, how you move to other branch?
git reset HEAD-3
how do i push branch to git repo?
git push -u origin chat
how to remove already pushed file to git?
git rm --cached chat.rb
also ignore from the system,
create a file .gitignore
and put a file there
How to combine 3-4 commits in 1?
git rebase -i HEAD-3
it will show you a file
pick 43223h added 4th line
pick 323j24 added 5th line
pick 343244 added 6th line
change below:
pick 43223h added 4th line
squash 323j24 added 5th line
squash 343244 added 6th line
how do you see how many commit you combined?
git diff-tree no-commit-id --name-only -r 7bcdss4324
how to merge a code of some-other branch in your branch?
git cherry-pick -x dsfsdf8f9dsf you can cherry pick in another branch
Fork
copy into your repo from any other repo.


No comments:
Post a Comment