-
Why Git?
-
There are other version control systems. There are a number of Version Control Systems out there. This alone should prove that version control is incredibly important. Examples
-
Git is the most popular and an industry standard.
-
It has some advantages over a centralized system, which has a single copy of the code:
- It's quick to take action on your own copy
- It works locally, on your own computer, and offline
- It makes having multiple branches, parallel worlds of code, easier
-
-
Git Gotchas
- Git can mean several things - the name of the source control technology, the functionality built into VS Code, the file formats and protocols that underlie the system.
- It’s both powerful (because it’s open-ended), plentiful (because it’s open source), and sometimes hard to use (because it’s open-ended).
- It takes practice, it's a learned skill, it's not intuitive - ask other developers about their Git disasters - everyone has a story.
-
Creating new repo and initial commit. The flow for using git starts with creating a directory (folder). The cycle as changes are made is
addandcommit. Record your changes in small chunks as you go.- Configure your git
git config --global user.email "youremail"git config --global user.name "yourname"
mkdir SampleApp- create new folder named SampleAppcd SampleApp- move to the project foldergit init- initialize the repositorytouch README.md- create a new filegit status- view the repository statusgit add .- stage the files to commit and tell get what files to track, "." selects all the new files or files with changesgit commit README.md -m "New readme file"- add the changes to the repo with the named file, "-m" indicates message included
- Configure your git
-
Create a new "Empty Activity" project in Android Studio and use the built-in git support (VCS menu). It doesn't have all the commands of Git Bash or the command line but is convenient when working in Android Studio.
-
Add a TEXT file called "myFile" (File/New/File)
-
Use "VCS > Enable Version Control Integration" to initialize a repository - choose "Git" as your VCS
-
Follow the git workflow
- View the repository status: using "Git>Commit" from the menu
- Stage the files to commit: select the "myFile" doc from the list (find it in the Unversioned Files list)
- Commit the changes with a comment: Type a commit message in the box, like "tests commit process in Android Studio" and click "Commit"
-
Review the effect using the Terminal
- Open the "Terminal" tab "View > Tool Windows > Terminal"
- Check out the changes with
git log - See the difference between
git logandgit log --oneline
- Fork and Clone this GitHub repository
- Use both the terminal and Android Studio to work with Git
- Push your changes to GitHub
- Submit the URL for your updated repo in Canvas
