Presentation is loading. Please wait.

Presentation is loading. Please wait.

GIT Version control. Version Control Sharing code via a centralized DB Also provides for Backtracking (going back to a previous version of code), Branching.

Similar presentations


Presentation on theme: "GIT Version control. Version Control Sharing code via a centralized DB Also provides for Backtracking (going back to a previous version of code), Branching."— Presentation transcript:

1 GIT Version control

2 Version Control Sharing code via a centralized DB Also provides for Backtracking (going back to a previous version of code), Branching (creating different versions) and Resolving differences in code updated by different programmers

3 Popular VCS Subversion Most open-source projects use Subversion as a repository because other larger projects, such as SourceForge, Apache, Python, Ruby and many others, use it as well. Google Code uses Subversion exclusively to distribute code. many different Subversion clients are available. Windows has Tortoise SVN Mac: Versions (a subversion client for mac) Xcode integrates a Subversion client

4 Popular VCS Git Initially developed by Linux kernel creator Linus Torvalds distributed version control system. There isn’t one centralized code base to pull the code from. Different branches hold different parts of the code. Used by Linux kernel, WINE, Fedora, etc. Most famous sites: github, bitbucket

5 Popular VCS Mercurial open-source distributed version control system, like Git. designed for larger projects, most likely outside the scope of designers and independent Web developers. extremely fast, and the creators built the software with performance as the most important feature. See http://mercurial.selenic.com/wiki/http://mercurial.selenic.com/wiki/ comes equipped with a stand-alone Web interface Easier to use than GIT

6 Popular VCS Other VCS: Bazzar (http://bazaar.canonical.com/en/ )http://bazaar.canonical.com/en/ LibreSource (http://dev.libresource.org )http://dev.libresource.org Monotone (http://www.monotone.ca )http://www.monotone.ca

7 Version Control with Git

8 Git

9

10 Git workflow

11 git: creating a local repository Can create a local (on your hard drive) git repository Via Xcode (option when you create a project) By hand Go to the project directory in the Terminal Create a.gitignore file (optional) Type the following commands on the command line: git init git add. git commit –m ‘Initial checkin’

12 remote repository a local repository is good when you’re the only developer if you’re sharing code, better to use a remote repository can create a remote repository and connect a local repository to it

13 Create a new remote repository at github In your user bar at the top right of any page, click the "Create a New Repo" button "Create a New Repo" button Or click on the “new repository” button: continued on next slide

14 github new repository Enter the name, description, public/private. Do not create a README, or a.gitignore file (though there is an option for a swift.gitignore file)

15 uploading local to remote In the terminal, go to the folder with your project. Create a local git repository by hand (see previous slide) In the terminal, do the following commands: git remote add origin “remote repository URL” # Sets the new remote git remote -v # Verifies the new remote URL will give you the URL of the remost repository that is associated with this git continued on next slide get this from your github site

16 uploading local to remote merge the remote with the local (necessary if created a README and/or a.gitignore file) git pull https://github.com/barrj/swiftSingleton.git now push the local files to the remote git push origin master # Pushes the changes in your local repository up to the remote repository you specified as the origin

17 Clone the git repository on your local hard drive Once the team leader has created the repository, others can clone that repository, then push/pull changes. Go to the place where the new folder will live Get the URL from the Git-Hub project git clone https://github.com/barrj/Intro_to_Classes.git This is the URL from the Git-Hub repository

18 Connect to a GitHub repository from your computer Another way of creating a git repository on your drive go to the folder that you’ll be using as your development folder. create a folder for this specific Repository (“Hello-World” in this example) by running the following command from your Terminal Window: mkdir Hello-World go into your new folder and run the following command from your Terminal: git init This will initialize a local Git Repository for you. Git must be installed on your computer already Now put a.gitignore file into the.git directory (see http://www.ithaca.edu/barr/Student/CS345/Examples/gitignore _example.txt ) http://www.ithaca.edu/barr/Student/CS345/Examples/gitignore _example.txt

19 Connect to a GitHub repository from your computer You should see a hidden folder called “.git” in your folder when you run the “ls –a” command. Next you need to link your local Git Repository to your remote GitHub Repository. To do this you will to run the following command: git remote add origin https://github.com/barrj/Intro_to_Classes.git You can get the URL from your GitHub repository. pull to get the initial files git pull origin master master indicates the master branch. If you want to start with a different branch, you must indicate this.

20 The state of your files Git has 6 states: Ignored Untracked : Git sees the file, but it’s neither in the repository nor staged for adding to the repository. Modified : Previous contents are in the repository, but this file won’t be added until it’s staged Staged : the file has been designated for inclusion in the next commit. Unmerged : you changed the file and attempted to pull in changes from another repository, and the two sets of changes couldn’t be reconciled. Git highlights the conflicts. You must resolve. Unmodified : file’s current state is what’s in the repository.

21 using git at the command line checking the status: > git status making changes: change a file then check status > git status On branch master Changes not staged for commit: (use "git add..." to update what will be committed) (use "git checkout --..." to discard changes in working directory) modified: singleton.xcodeproj/project.xcworkspace/xcuserdata/barr.xcuserdatad/UserI nterfaceState.xcuserstate modified: singleton/SecondViewController.swift no changes added to commit (use "git add" and/or "git commit -a") hint about what to do

22 using git at the command line tell git to stage the changes: > git add SecondViewController.swift will add a particular file to be committed to the repository > git add –A # adds all new and updated or > git add. # adds all new files > git add –u # adds all updated files don’t always want to add all the changes to the repository at this time!

23 using git at the command line now check git status : > git status On branch master Changes to be committed: (use "git reset HEAD..." to unstage) modified: singleton.xcodeproj/project.xcworkspace/xcuserdata/barr.xcuserdatad/UserInte rfaceState.xcuserstate modified: singleton/SecondViewController.swift Changes have been staged. Means git knows about the changes but has not yet added the changes to the repository

24 using git at the command line Now must commit the changes to the repository: > git commit –m ‘message’ if you leave off the “-m message” you are popped into an editor of your choice (you can change this) to add a commit message. when you leave that editor, the changes are committed to the local repository but not pushed to the remote repository.

25 using git at the command line Now must push the changes to the remote repository: > git push all the committed changes will be pushed to the remote directory the optional is the URL of a remote repository to commit to. Not necessary if you’ve set things up correctly. the optional allows you to create a new branch To see a history of git actions use the command: > git log

26 using git at the command line When you start working you need to get the latest code from the repository. Do this with the pull command: > git pull all the changes from the URL will be downloaded. If is specified, changes from that branch will be downloaded.

27 using git at the command line If you have problems pulling or pushing, you can checkout versions and update them git checkout --ours filename.c git checkout --theirs filename.c git add filename.c git commit -m "using theirs” Now will be able to push/pull

28 using git at the command line Other useful commands: git merge will merge two different branches together into one git branch XXX will create a new branch with name XXX git –checkout Updates files in the working tree to match the version in the index or the specified tree. If no paths are given, git checkout will also update HEAD to set the specified branch as the current branch. See the git reference at http://git-scm.com/docshttp://git-scm.com/docs


Download ppt "GIT Version control. Version Control Sharing code via a centralized DB Also provides for Backtracking (going back to a previous version of code), Branching."

Similar presentations


Ads by Google