List of git commands that we might need when working with git.
In local machine after installing git:
git log #Log of our repo
git clone repo #To take a copy from repository in git hub to our local machine
git checkout <commitid> #To a detached headstate
For details on detached head state please check this link
git diff <first commit id> < second commit id>
git init
git status
--Commands to add files to staging area
git add 'filename1'
git add 'filename2'
git status
git commit -m "Comment"
git diff <workingdir> <Staging dir>
git diff --staged #to diff between staging and repo
git reset --hard #to revert to previous commit ,to make master point to some previous commit
Branches:
git branch <branch-name>
git checkout <branch-name>
git log --graph --oneline branchname branchaname
[git checkout -b <branchname>
equals to following two commands
git branch <newbranchname>
git checkout <newbranchname>]
Merge :
git merge <b1> <b2>
Diff between a commit and parent with out knowing it's parent id
git show <commitid>
Delete a branch:
git branch -d <branchname>
Remote branch:
git remote add origin url
git remote
git remote -v
git push origin master
Pull branch:
git pull origin master
git log #to update the remote to local and check if updates happens.
Fork a repo:
Merging remote changes:
If remote and local has changes on same file.During conflicts, use fetch.
git fetch origin
git merge master origin/master
origin/master points to the remote repository on git hub
Pull request commands:
git branch newbranchname
git checkout newbranchname
git checkout master
git add 'filename'
git commit
git push origin <newbranchname>
Clone Remote and cross -repo conflicts:
git remote add upstream 'original repo'
git checkout master
git pull upstream master
git checkout 'anotherbranch'
origin - forked repo
upstream - original repo
Merge newbranch with master
git merge master 'anotherbranch'
git add
git commit
git push origin 'anotherbranch'
Delete a remote branch:
git branch --remote
git push origin --delete <branch-name>
In local machine after installing git:
git log #Log of our repo
git clone repo #To take a copy from repository in git hub to our local machine
git checkout <commitid> #To a detached headstate
For details on detached head state please check this link
git diff <first commit id> < second commit id>
git init
git status
--Commands to add files to staging area
git add 'filename1'
git add 'filename2'
git status
git commit -m "Comment"
git diff <workingdir> <Staging dir>
git diff --staged #to diff between staging and repo
git reset --hard #to revert to previous commit ,to make master point to some previous commit
Branches:
git branch <branch-name>
git checkout <branch-name>
git log --graph --oneline branchname branchaname
[git checkout -b <branchname>
equals to following two commands
git branch <newbranchname>
git checkout <newbranchname>]
Merge :
git merge <b1> <b2>
Diff between a commit and parent with out knowing it's parent id
git show <commitid>
Delete a branch:
git branch -d <branchname>
Remote branch:
git remote add origin url
git remote
git remote -v
git push origin master
Pull branch:
git pull origin master
git log #to update the remote to local and check if updates happens.
Fork a repo:
Merging remote changes:
If remote and local has changes on same file.During conflicts, use fetch.
git fetch origin
git merge master origin/master
origin/master points to the remote repository on git hub
Pull request commands:
git branch newbranchname
git checkout newbranchname
git checkout master
git add 'filename'
git commit
git push origin <newbranchname>
Clone Remote and cross -repo conflicts:
git remote add upstream 'original repo'
git checkout master
git pull upstream master
git checkout 'anotherbranch'
origin - forked repo
upstream - original repo
Merge newbranch with master
git merge master 'anotherbranch'
git add
git commit
git push origin 'anotherbranch'
Delete a remote branch:
git branch --remote
git push origin --delete <branch-name>
No comments:
Post a Comment