What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git...
Transcript of What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git...
What is version control?
I Keeps track of changes to your code.
I You don’t have to worry about accidentally losing or deletingcode.
I You can experiment and reset to a known good state.
I Makes collaborating with others easier.
What is git?
I ‘the stupid content tracker’
I Distributed - everything is kept on your local machine.
I ‘Repository’ - a collection of code and history.
I ‘Commit’ - a chunk of saved changes.
What is version control?
I Keeps track of changes to your code.
I You don’t have to worry about accidentally losing or deletingcode.
I You can experiment and reset to a known good state.
I Makes collaborating with others easier.
What is git?
I ‘the stupid content tracker’
I Distributed - everything is kept on your local machine.
I ‘Repository’ - a collection of code and history.
I ‘Commit’ - a chunk of saved changes.
Getting Started
I git init Makes a new empty git repository.
I git add FILE Adds changes in FILE to the next commit.
I git status Shows the status of the repository.
I git config --global user.name NAME
I git config --global user.email EMAIL
I git config --global core.editor vim
Getting Started
I git init Makes a new empty git repository.
I git add FILE Adds changes in FILE to the next commit.
I git status Shows the status of the repository.
I git config --global user.name NAME
I git config --global user.email EMAIL
I git config --global core.editor vim
Committing
git commit -m ‘‘a’’
amaster
Committing
git commit -m ‘‘b’’
a
bmaster
Committing
git commit -m ‘‘c’’
a
b
cmaster
Branching
git checkout -b new-branch
a
b
c
master
new-branch
Branching
git commit -m ‘‘d’’
a
b
c
d
master
new-branch
Branching
a
b
c
d
master
new-branch HEAD
Branching
git checkout master
a
b
c
d
master
new-branch
HEAD
Branching
git checkout -b another
a
b
c
d
master
new-branch
HEADanother
Branching
git commit -m ‘‘e’’
a
b
c
d e
master
new-branch HEADanother
Merging
git merge new-branch
a
b
c
d e
master
new-branch HEADanother
Merginggit merge new-branch
a
b
c
d e
d+e
master
new-branch
Merginggit merge new-branch
a
b
c
d e
d+e
master
new-branch
HEADanother
Merginggit merge master
Nothing to do!a
b
c
d e
d+e
master
new-branch
HEADanother
Merginggit checkout master
a
b
c
d e
d+e
master
new-branch
another
HEAD
Merginggit merge another
a
b
c
d e
d+e
master
new-branch
HEADanother
Merge conflicts
CONFLICT (content): Merge conflict in the-file.txt
Automatic merge failed; fix conflicts and then commit
the result.
In the-file.txt :<<<<<<< HEAD
The current branch’s contents
=======
Stuff from the branch you’re merging
>>>>>>> new-branch
git add the-file.txt and git commit
Merge conflicts
CONFLICT (content): Merge conflict in the-file.txt
Automatic merge failed; fix conflicts and then commit
the result.
In the-file.txt :<<<<<<< HEAD
The current branch’s contents
=======
Stuff from the branch you’re merging
>>>>>>> new-branch
git add the-file.txt and git commit
Merge conflicts
CONFLICT (content): Merge conflict in the-file.txt
Automatic merge failed; fix conflicts and then commit
the result.
In the-file.txt :<<<<<<< HEAD
The current branch’s contents
=======
Stuff from the branch you’re merging
>>>>>>> new-branch
git add the-file.txt and git commit
Looking at stuff
I git log Show a log of commits
I --graph Neat ASCII graph
I -p Show what changed in each commit
I git diff Show uncommitted changes
I gitk Graphical log
I --all Show all branches
I git gui Graphical tool for committing
Looking at stuff
I git log Show a log of commits
I --graph Neat ASCII graph
I -p Show what changed in each commit
I git diff Show uncommitted changes
I gitk Graphical log
I --all Show all branches
I git gui Graphical tool for committing
Looking at stuff
I git log Show a log of commits
I --graph Neat ASCII graph
I -p Show what changed in each commit
I git diff Show uncommitted changes
I gitk Graphical log
I --all Show all branches
I git gui Graphical tool for committing
Working with remotes
I git clone REPO LOCATION makes a copy of a repository.
I git push Pushes changes from your current branch to theremote branch it tracks.(You may need to rungit config --global push.default simple .)
I git pull Pulls changes from the remote branch and mergesthem into your current branch.
I git remote add REMOTE NAME REPO LOCATION adds aremote to an existing repository.
Working with remotes
I git clone REPO LOCATION makes a copy of a repository.
I git push Pushes changes from your current branch to theremote branch it tracks.(You may need to rungit config --global push.default simple .)
I git pull Pulls changes from the remote branch and mergesthem into your current branch.
I git remote add REMOTE NAME REPO LOCATION adds aremote to an existing repository.
Working with remotes
I git clone REPO LOCATION makes a copy of a repository.
I git push Pushes changes from your current branch to theremote branch it tracks.(You may need to rungit config --global push.default simple .)
I git pull Pulls changes from the remote branch and mergesthem into your current branch.
I git remote add REMOTE NAME REPO LOCATION adds aremote to an existing repository.
Git Tips
I Make your commit messages descriptive!
I Don’t add generated files (like a.out ) to your repo.
I You can ignore certain files by putting their names in a.gitignore file in your repo.
I When collaborating, work on separate branches and merge asyou go along.
I git help COMMAND will show you documentation.
Git Tips
I Make your commit messages descriptive!
I Don’t add generated files (like a.out ) to your repo.
I You can ignore certain files by putting their names in a.gitignore file in your repo.
I When collaborating, work on separate branches and merge asyou go along.
I git help COMMAND will show you documentation.
Git Tips
I Make your commit messages descriptive!
I Don’t add generated files (like a.out ) to your repo.
I You can ignore certain files by putting their names in a.gitignore file in your repo.
I When collaborating, work on separate branches and merge asyou go along.
I git help COMMAND will show you documentation.