16
Version Control Code Repositories CLion, Git, BitBucket (in Linux)

Version Control Code Repositorieskatrompas.accprofessors.com/assets/downloads/VersionControlCod… · Git is an example of version control. Code Repository: a file archive and web

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Version Control Code Repositorieskatrompas.accprofessors.com/assets/downloads/VersionControlCod… · Git is an example of version control. Code Repository: a file archive and web

Version ControlCode Repositories

CLion, Git, BitBucket(in Linux)

Page 2: Version Control Code Repositorieskatrompas.accprofessors.com/assets/downloads/VersionControlCod… · Git is an example of version control. Code Repository: a file archive and web

Version Control and Code Repositories● Version Control: a system that records changes to a file or set of files over

time so that you can recall specific versions later. Git is an example of version control.

● Code Repository: a file archive and web hosting facility where source code is kept, either publicly or privately. A code repository includes version control.

Do not confuse version control utilities such as Git with repositories such as BitBucket. Git is version control. BitBucket is where you can archive your code including versioning that archive, and also work collaboratively.

NOTE: This tutorial assumes you start with a local project you want to add to a remote repository. The process for the reverse case, or for cloning an existing repository, would be different but the same principles apply.

Page 3: Version Control Code Repositorieskatrompas.accprofessors.com/assets/downloads/VersionControlCod… · Git is an example of version control. Code Repository: a file archive and web

Initialize Git● Inside the root of your project directory, at the command type ‘git init’● This creates an EMPTY local version control system.● You will now see a .git folder. This is your local version control system.● Do not touch .git, it’s not for you, it’s for Git.

Page 4: Version Control Code Repositorieskatrompas.accprofessors.com/assets/downloads/VersionControlCod… · Git is an example of version control. Code Repository: a file archive and web

.gitignore and CLion view● If you look at your project in CLion, you will see the files are now color coded. They are red. This

indicates they have not been added to version control.● DO NOT ADD THEM at this point. You want to .gitignore first. Some files you do not want to add to

the VCS, so create a .gitignore file and list all your files and directories to be ignored.

Page 5: Version Control Code Repositorieskatrompas.accprofessors.com/assets/downloads/VersionControlCod… · Git is an example of version control. Code Repository: a file archive and web

.gitignore - another approachThe other (and possibly better way) to do that would be to create a .gitignore by first ignoring all, then unignore .cpp and .h like this in your .gitignore

Page 6: Version Control Code Repositorieskatrompas.accprofessors.com/assets/downloads/VersionControlCod… · Git is an example of version control. Code Repository: a file archive and web

.git add and CLion view● Now you can add files to your version control.

Based on the configuration so far, only .cpp and .h files will be added.

● Your files will turn green in CLion. This indicates they are added but NOT committed. Files must be added and committed to be tracked in version control.

Page 7: Version Control Code Repositorieskatrompas.accprofessors.com/assets/downloads/VersionControlCod… · Git is an example of version control. Code Repository: a file archive and web

Commit Files● At this point you can keep working in the command line or you can use

the VCS in the IDE (you could have done everything so far in the IDE)● Some people prefer to switch to the IDE at this point and use the GUI

but the command line is just as good. Most people use both as needed.● Select VCS → Commit and select options (if any), write your commit

message, and press Commit.● Now your files will show no color, indicating they are added, committed

and are unchanged.

Page 8: Version Control Code Repositorieskatrompas.accprofessors.com/assets/downloads/VersionControlCod… · Git is an example of version control. Code Repository: a file archive and web

Local Done! Now you can see changes in the IDE.● At this point your local version control is set up. You could stop here and only work

locally. Even if you don’t need a remote repo, you should ALWAYS do this much.● This will allow you to track changes, revert code if needed, and compare versions (diff).● However this will not yet give you a backup (remote repo) or allow you to collaborate

with others. For that you need a remote repo like Github or BitBucket.

Changes are tracked in color in the IDE.

● Green for added code.● Blue for changed code.● Red arrow showing

deleted code.

Page 9: Version Control Code Repositorieskatrompas.accprofessors.com/assets/downloads/VersionControlCod… · Git is an example of version control. Code Repository: a file archive and web

Remote Repo● Go to https://bitbucket.com and create an account (if you don’t have one).● Make a repo. DO NOT make a Readme File, the repo MUST be empty.

Now you have an empty repo on bitbucket.

● It will tell you could clone from someplace else or push back to your local. DO NOT DO THESE.

● You want to simply connect your local repo with your remote.

Page 10: Version Control Code Repositorieskatrompas.accprofessors.com/assets/downloads/VersionControlCod… · Git is an example of version control. Code Repository: a file archive and web

Connecting local and remote - You should see this now.DO NOT CREATE A README OR .gitignore

You need an empty remote repo and you already have a local .gitignore

Page 11: Version Control Code Repositorieskatrompas.accprofessors.com/assets/downloads/VersionControlCod… · Git is an example of version control. Code Repository: a file archive and web

Pushing Code to Remote Repo

Page 12: Version Control Code Repositorieskatrompas.accprofessors.com/assets/downloads/VersionControlCod… · Git is an example of version control. Code Repository: a file archive and web

Set-up Done● Your local version control is set-up.● You remote repository and version control is set-up.● You have connected them.● Now you can work locally and when you have completed and tested a section

of code that you want to commit, you commit it locally, and push it to the remote repo.

● You can also change your code in the remote repo and pull the changes.● Other can now also clone your remote repo, work in their local copy, push

their changes to the repo. You can then pull their changes back to your local repo so you keep up with other developer’s changes.

Page 13: Version Control Code Repositorieskatrompas.accprofessors.com/assets/downloads/VersionControlCod… · Git is an example of version control. Code Repository: a file archive and web

Working - Commit Code Locally

Page 14: Version Control Code Repositorieskatrompas.accprofessors.com/assets/downloads/VersionControlCod… · Git is an example of version control. Code Repository: a file archive and web

Working - Push to Remote Repo

Page 15: Version Control Code Repositorieskatrompas.accprofessors.com/assets/downloads/VersionControlCod… · Git is an example of version control. Code Repository: a file archive and web

Working - View Your Changes Remotely

Page 16: Version Control Code Repositorieskatrompas.accprofessors.com/assets/downloads/VersionControlCod… · Git is an example of version control. Code Repository: a file archive and web

Good LuckYou’ll need it.