Skip to content

Commit 5371e01

Browse files
committed
updating README.md with new links
1 parent ced8c70 commit 5371e01

13 files changed

+741
-222
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#### Pulling the latest update from a specific branch
2+
3+
The **pull** command is used to download and integrate remote changes. The target (to which branch the data should be integrated into) is always the currently checked out HEAD branch.
4+
The source (from which branch the data should be downloaded from) can be specified in the command’s options.
5+
6+
**Before using “git pull”, make sure the correct local branch is checked out. Then, to perform the pull, simply specify which remote branch you want to integrate. Assuming I am in ‘master’ branch in my local machine, and I want to incorporate changes from a remote repository’s ‘dev’ branch into the local machine’s branch.**
7+
8+
```
9+
git checkout dev
10+
git pull origin dev
11+
```
12+
13+
The branch-name option can be omitted, however, if a tracking relationship with a remote branch is set up. In most cases, however, your local branch will already have a proper tracking connection with a remote branch set up. This configuration provides default values so that the pull command already knows where to pull from without any additional options:
14+
15+
```
16+
git pull
17+
```
18+
19+
It’s often clearer to separate the two actions git pull does. The first thing it does is update the local tracking branch that corresponds to the remote branch. This can be done with git fetch.
20+
The second is that it then merges in changes, so in its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD.
21+
22+
More precisely, git pull runs git fetch with the given parameters and calls git merge to merge the retrieved branch heads into the current branch. With — rebase, it runs git rebase instead of git merge.
23+
24+
25+
#### How do I force “git pull” to overwrite local files?
26+
27+
Important: If you have any local changes, they will be lost. With or without --hard option, any local commits that haven't been pushed will be lost
28+
29+
git fetch --all
30+
31+
Then, you have two options:
32+
33+
``git reset --hard origin/master``
34+
35+
OR If you are on some other branch:
36+
37+
`git reset --hard origin/<branch_name>`
38+
39+
git fetch downloads the latest from remote without trying to merge or rebase anything.
40+
41+
Then the git reset resets the master branch to what you just fetched. The --hard option changes all the files in your working tree to match the files in origin/master.
42+
43+
#### Another option is git stash
44+
45+
Uncommitted changes, however (even staged), will be lost. Make sure to stash and commit anything you need.
46+
47+
For that you can run the following:
48+
49+
`git stash`
50+
51+
And then to reapply these uncommitted changes:
52+
53+
`git stash pop`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
First note the first-principle constructor of a Promise - How to create and make a function that returns a Promise
2+
3+
```js
4+
const createdPromise = new Promise((resolve, reject) => {
5+
// do a thing, possibly async, then…
6+
7+
if (/* everything turned out fine */) {
8+
resolve("Stuff worked!");
9+
}
10+
else {
11+
reject(Error("It broke"));
12+
}
13+
});
14+
```

Promise-Async-Await-Sequential-Execution/Promise-async-await-master-notes/promise-basic-implementation.js renamed to Promise-Async-Await-Sequential-Execution/Promise-Super-Basic/Promise-super-basic-implementation-GOOD-To-Start-with.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
// Both .then and .catch will return a new promise. That seems like a small detail but it’s important because it means that promises can be chained.
22

3-
let promise1 = new Promise((resolve, reject) => {
4-
reject();
3+
let promise2 = new Promise((resolve, reject) => {
4+
resolve();
55
});
66

7-
promise1
7+
promise2
88
.then(() => {
99
console.log("Hey I am finished executing resolved()");
1010
})
1111
.catch(() => {
1212
console.log("Hey this time rejected, but will hit again");
1313
});
1414

15-
// The above Will output - "Hey this time rejected, but will hit again"
15+
// The above Will output - Hey I am finished executing resolved()
1616

17-
let promise2 = new Promise((resolve, reject) => {
18-
resolve();
17+
let promise1 = new Promise((resolve, reject) => {
18+
reject();
1919
});
2020

21-
promise2
21+
promise1
2222
.then(() => {
2323
console.log("Hey I am finished executing resolved()");
2424
})
2525
.catch(() => {
2626
console.log("Hey this time rejected, but will hit again");
2727
});
2828

29-
// The above Will output - Hey I am finished executing resolved()
29+
// The above Will output - "Hey this time rejected, but will hit again"
3030

3131
let promise3 = new Promise((resolve, reject) => {
3232
reject();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
First note the first-principle constructor of a Promise - How to create and make a function that returns a Promise
2+
3+
```js
4+
const createdPromise = new Promise((resolve, reject) => {
5+
// do a thing, possibly async, then…
6+
7+
if (/* everything turned out fine */) {
8+
resolve("Stuff worked!");
9+
}
10+
else {
11+
reject(Error("It broke"));
12+
}
13+
});
14+
```
15+
16+
#### Now first Implementation - When Success case need to be returned
17+
18+
```js
19+
const promise = new Promise((resolve, reject) => {
20+
// do a thing, possibly async, then…
21+
22+
if (1 === 1) {
23+
resolve("Stuff worked!");
24+
} else {
25+
reject(Error("It broke"));
26+
}
27+
});
28+
```
29+
30+
Will output the below
31+
32+
```
33+
Stuff worked!
34+
35+
```
36+
37+
#### Now Second Implementation - When Error need to be returned
38+
39+
```js
40+
const promise = new Promise((resolve, reject) => {
41+
// do a thing, possibly async, then…
42+
43+
if (1 === 2) {
44+
resolve("Stuff worked!");
45+
} else {
46+
reject(Error("It broke"));
47+
}
48+
});
49+
50+
promise.then(
51+
result => {
52+
console.log(result); // "Stuff worked!"
53+
},
54+
function(err) {
55+
console.log(err); // Error: "It broke"
56+
}
57+
);
58+
```
59+
60+
The above will output the below
61+
62+
```
63+
Error: It broke
64+
at Promise (/home/rohan/codeLap/js/challenges/challenges-May-19/JS-Python_Challenges/test-code-1.js:19:12)
65+
at new Promise (<anonymous>)
66+
at Object.<anonymous> (/home/rohan/codeLap/js/challenges/challenges-May-19/JS-Python_Challenges/test-code-1.js:12:17)
67+
at Module._compile (module.js:652:30)
68+
at Object.Module._extensions..js (module.js:663:10)
69+
at Module.load (module.js:565:32)
70+
at tryModuleLoad (module.js:505:12)
71+
at Function.Module._load (module.js:497:3)
72+
at Function.Module.runMain (module.js:693:10)
73+
at startup (bootstrap_node.js:188:16)
74+
```

Promise-Async-Await-Sequential-Execution/Promise-async-await-master-notes/Promise-simple-Example.js

+43-51
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,30 @@ const isMomHappy = true;
22

33
// Define a function to return a Promise
44
const willIGetNewPhone = new Promise((resolve, reject) => {
5-
if (isMomHappy) {
6-
const phone = {
7-
brand: "Samsung",
8-
color: "black"
9-
};
10-
resolve(phone);
11-
} else {
12-
const reason = new Error("Mon is not happy");
13-
reject(reason);
14-
}
5+
if (isMomHappy) {
6+
const phone = {
7+
brand: "Samsung",
8+
color: "black"
9+
};
10+
resolve(phone);
11+
} else {
12+
const reason = new Error("Mom is not happy");
13+
reject(reason);
14+
}
1515
});
1616

1717
const showOff = phone => {
18-
const message =
19-
"Hey friend, I have a new " +
20-
phone.color +
21-
" " +
22-
phone.brand +
23-
" phone";
24-
return Promise.resolve(message);
18+
const message =
19+
"Hey friend, I have a new " + phone.color + " " + phone.brand + " phone";
20+
return Promise.resolve(message);
2521
};
2622

2723
// call out promise
2824
const askMom = () => {
29-
willIGetNewPhone
30-
.then(showOff)
31-
.then(fullfilled => console.log(fullfilled))
32-
.then(error => console.log(error.message));
25+
willIGetNewPhone
26+
.then(showOff)
27+
.then(fullfilled => console.log(fullfilled))
28+
.then(error => console.log(error.message));
3329
};
3430

3531
askMom();
@@ -40,50 +36,46 @@ askMom();
4036

4137
// Promise
4238
const willIGetNewPhone = new Promise((resolve, reject) => {
43-
if (isMomHappy) {
44-
const phone = {
45-
brand: "Samsung",
46-
color: "black"
47-
};
48-
resolve(phone);
49-
} else {
50-
const reason = new Error("mom is not happy");
51-
reject(reason);
52-
}
39+
if (isMomHappy) {
40+
const phone = {
41+
brand: "Samsung",
42+
color: "black"
43+
};
44+
resolve(phone);
45+
} else {
46+
const reason = new Error("mom is not happy");
47+
reject(reason);
48+
}
5349
});
5450

5551
// 2nd promise
5652
async function showOff(phone) {
57-
return new Promise((resolve, reject) => {
58-
var message =
59-
"Hey friend, I have a new " +
60-
phone.color +
61-
" " +
62-
phone.brand +
63-
" phone";
53+
return new Promise((resolve, reject) => {
54+
var message =
55+
"Hey friend, I have a new " + phone.color + " " + phone.brand + " phone";
6456

65-
resolve(message);
66-
});
57+
resolve(message);
58+
});
6759
}
6860

6961
// call our promise
7062
async function askMom() {
71-
try {
72-
console.log("before asking Mom");
63+
try {
64+
console.log("before asking Mom");
7365

74-
let phone = await willIGetNewPhone;
75-
let message = await showOff(phone);
66+
let phone = await willIGetNewPhone;
67+
let message = await showOff(phone);
7668

77-
console.log(message);
78-
console.log("after asking mom");
79-
} catch (error) {
80-
console.log(error.message);
81-
}
69+
console.log(message);
70+
console.log("after asking mom");
71+
} catch (error) {
72+
console.log(error.message);
73+
}
8274
}
8375

8476
(async () => {
85-
await askMom();
77+
await askMom();
8678
})();
8779

88-
/*Further Reading -
80+
/*Further Reading -
8981
[https://scotch.io/tutorials/javascript-promises-for-dummies](https://scotch.io/tutorials/javascript-promises-for-dummies)*/

0 commit comments

Comments
 (0)