My software never has bugs.
It just develops random features.
http://explainxkcd.com/wiki/index.php/1597:_Git
Comes pre-installed
Should come pre-installed
sudo apt-get install git-all
sudo yum install git-all
$ git init [project-name]
creates a new Git repository
* if repo does not already exist
re·pos·i·to·ry
noun
a central location in which data is stored
and managed.
"the metadata will be aggregated in a repository"
Connects your local repository to a remote instance
(eg. Github, BitBucket, personal)
* if repo does not already exist
$ git remote add origin [url]
Copies existing repository files to your machine
NOTES:
$ git clone [url]
Add or remove files to a
"staging index" for commiting
$ git add [file]
$ git rm [file]
$ git add .
Question:
why use instead of ?
git add . git add *
To be answered later...
$ git commit -m "[message]"
Saves a snapshot of the changes ("delta")
made to your files and when.
The message should be relevant and significant.
C0
C1
https://explainxkcd.com/wiki/index.php/1296:_Git_Commit
Let git forget about and ignore non-critical files.
$ touch .gitignore
$ git add .gitignore
$ git commit -m "Add gitignore"
Thumbs.db, .DS_Store, ._*
*.sublime-workspace, *.idea/
Question:
why use instead of ?
git add . git add *
The latter does not respect the .gitignore!
Update remote repo with associated changes
$ git push
You could specify where to point your changes to
$ git push origin master
$ git push -u origin otherremote
but you probably will never need to.
This changes your local files.
$ git pull
implicitly does a and then
git pull git fetch git merge
Reports what changes have been made to the remote.
This does not change your local files.
$ git fetch
Branch early, and branch often!
$ git branch new-branch-name
Simply points to a specific commit from history.
Default branch is called
master
$ git branch -b newbranch
is shorthand for
$ git branch newbranch
$ git checkout newbranch
checkout switches to the specified branch and updates the working directory
C0
C1
C2
B1
$ git merge other-branch
Simply points to a specific commit
Create a new branch, develop a new feature,
and combine it back in
C0
C1
C2
C3
B1
$ git merge other-branch
If the same part of the same file changed differently in the two branches being merged, Git can't merge them cleanly
Git adds conflict-resolution markers so you can identify
them and manually resolve those conflicts
<<<<<<< HEAD:index.html
<div id="footer">contact : support@email.com</div>
=======
<div id="footer">
please contact us at support@email.com
</div>
>>>>>>> newbranch:index.html
Once resolved, simply commit to finish the merge...
<div id="footer">contact us at support@email.com</div>
$ git commit Merge branch 'newbranch' Conflicts: index.html # # It looks like you may be committing a merge. # If this is not correct, please remove the file # .git/MERGE_HEAD # and try again. # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch master # All conflicts fixed but you are still merging. # # Changes to be committed: # modified: index.html #
$ git status
$ git diff [file]
Lists all new or modified files to be commited
Shows file differences not yet staged
master
feature
master
feature 1
feature 2
master
feature 1
feature 2
Protip: Merge master into feature, and then feature back to master.
master
develop
hotfix
release
feature
1.0.0
1.0.1
1.1.1
git init
git remote add https://...
git add .
git commit -m "msg"
git clone https://...git
git add .
git commit -m "msg"
$ git config --global user.name "John Doe"
$ git config --global user.email "e@mail.co"