Last active
June 11, 2017 23:35
-
-
Save yoyozi/2dcbef3e0ec5ec5a8f3347ea400eb855 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Innitialize Git | |
$ git config --global user.name "Your Name" | |
$ git config --global user.email [email protected] | |
$ git init | |
$ git add -A | |
The added files are initially placed in a staging area, which contains pending | |
changes to our project. We can see which files are in the staging area using | |
the status command: | |
$ git status | |
if we delete file and want to roll back use | |
$ git checkout -f | |
Pushing up the repo | |
git remote add origin https://github.com/yoyozi/hello_app.git | |
git push -u origin master | |
$ git checkout -b modify-README | |
Switched to a new branch 'modify-README' | |
$ git branch (lists all branches) | |
$ git checkout master | |
Switched to branch 'master' | |
$ git merge modify-README | |
$ git branch -d modify-README | |
Deleted branch modify-README (was 9dc4f64). | |
As mentioned above, it’s also possible to abandon your topic branch changes, in | |
this case with git branch -D: | |
For illustration only; don't do this unless you mess up a branch | |
$ git checkout -b topic-branch | |
$ <really mess up the branch> | |
$ git add -A | |
$ git commit -a -m "Make major mistake" | |
$ git checkout master | |
$ git branch -D topic-branch | |
Unlike the -d flag, the -D flag will delete the branch even though we haven’t | |
merged in the changes | |
$ git push | |
Pushes changes up to git | |
///////// To rollback to a specific commit /////// | |
Make a copy of the branch at its current state: | |
git branch crazyexperiment | |
(The git branch <name> command will leave you with your current branch still checked out.) | |
Reset your current branch to your desired commit with git reset: | |
git reset --hard c2e7af2b51 | |
(Replace c2e7af2b51 with the commit that you want to go back to.) | |
When you decide that your crazy experiment branch doesn't contain anything useful, you can delete it with: | |
git branch -D crazyexperiment | |
// to see a list of merged branched or unmerged branches | |
The useful --merged and --no-merged options can filter this list to branches that you have or have not yet merged into | |
the branch you’re currently on. To see which branches are already merged into the branch you’re on, | |
you can run git branch --merged: | |
➜ carles git:(newusdzar) ✗ git branch -v | |
brokenit 5dc2cf1 [ahead 1] broken | |
master fcf17f6 Added bootstrap and Navbar with updated source | |
* newusdzar fcf17f6 Added bootstrap and Navbar with updated source | |
➜ carles git:(newusdzar) ✗ git branch --no-merged | |
brokenit | |
➜ carles git:(newusdzar) ✗ git branch --merged | |
master | |
* newusdzar | |
➜ carles git:(newusdzar) ✗ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment