September 29, 2020

How to work between local repository and Remote repository

 Firstly you have to create an account on github and then create an empty repository . You can go for public or private.

Once you created a repo, the next step will be to include in your local repo.

go to your terminal where you want to add your remote repo.

newproject(master)> git remote add origin http://-----------------------------------(url)

> cat .git/config

> git branch 

> git branch -r 

It is now tracked with your local repo.

if you want to push your code to remote repo . Do this step-

> git push -u origin master 

> git branch 

> git branch -a 

Now let's sat we want to add that project in my computer not in same folder. assume my Colleauge work - 

> git clone http://----------  newproject 

then newproject folder will be created with all the cloned project '

newproject(master)> ls -la

How to track remote branches -

mainproject(master)>git branch non-tracking

> git push origin non-tracking

We have to specify the remote branch now 

Set up to track remote branch from origin'

>git branch -u origin/non-tracking non-tracking

for non tracking we can use this command-

> git branch --unset -upstream non-tracking

Push changes to Remote Repo-

Before push we have to amke some changes 

mainproject(master)> git commit -am "changes are done"

>git log --oneline -5 origin/master

>git log diff origin/master..master 

> git push 

origin/master is tracking branch 

> git log --oneline origin/master 

Fetch the changes from remote repo-

newproject(master)> git log 

>git log orgin/master

>git branch

>git branch -r

>git Fetch

>git log --oneline origin/master 

now master branch will not change 

we have to merge in fetched changes -

> git diff origin/master..master 

>git merge origin/master 

>git log --oneline origin/master

Basically git Fecth + Merge = Pull

Check out Remote branches -

newproejct (master)> git branch non-tracking origin/non-tracking

>git log --oneline non-tracking

>cat .git/config

> git branch -d non-tracking 

>git checkout  -b non-tracking origin/non-traking

>git checkout master 

>git commit -am "new changes "

> git push 

Delete a Remote Branch-

git push origin : non-tracking

2nd method- git push origin --delete non-traking 

====================================================================


Let take an example - My work and / My collegue work 


My Work- git checkout master 

>git fetch 

>git merge origin/master 

>git checkout -b newbranch 

>git commit -am "new changes"

> git fetch

>git push -u origin newbranch 

======================================

My Collegue Work == cheking the remote repo what changes ahs been dine in new rep and make new changes in that branch and agin push to remote repo.

git checkout master 

git fetch 

git merge origin/master 

git chekout -b newbranch origin/newbranch 

git log

git show SHA

git commit -am 

git Fetch

git push 

===================================

My Work= check if i want to see my colleuge work and want to make some changes '

>git fetch 

>git log -p newbranch..origin/newbranch

>git merge orgin ./newbranch 

git checkout master 

git fetch 

git merge origin/master 

git merge newbranch 

git push 

=======================================




































 


No comments:

Post a Comment

Please let me know if you have any doubts.

Key concepts in Pipeline

 1. Agent- To build your code or deploy your software using azure pipelines, you need at least one agent. Two types of agent- Microsoft host...