Android Tutorial Using a Git Repository (Version Control) for Beginners

Discussion in 'Tutorials & Examples' started by wonder, Jun 21, 2017.

  1. wonder

    wonder Expert Licensed User

    git logo.png

    What is Version Control?

    Version control software keeps track of every modification to the code in a special kind of database. If a mistake is made, developers can turn back the clock and compare earlier versions of the code to help fix the mistake while minimizing disruption to all team members.
    (read more...)

    What is Git?
    By far, the most widely used modern version control system in the world today is Git. Git is a mature, actively maintained open source project originally developed in 2005 by Linus Torvalds, the famous creator of the Linux operating system kernel.
    (read more...)

    What is a Repository?
    In software development, a repository is a central file storage location. It is used by version control systems to store multiple versions of files. While a repository can be configured on a local machine for a single user, it is often stored on a server, which can be accessed by multiple users.
    (read more...)

    How do I get started?
    First, you'll need to install Git for Windows.
    Once installed, you can already start using it locally, but if you want to safely secure your files online, it's time now to choose an online repository.
    There are many available options such as GitHub, GitLab or Bitbucket.
    For this tutorial, we'll be rolling with GitLab, since it allows you to have free private repositories.

    How do I use Git on Windows?
    Right-click you project's folder. Click "Git Bash here".
    context menu.png
    You are now using a Bash shell (Linux), on Windows. Pretty cool, eh?
    Alright, back to the point!

    To turn your project folder into a local git repository, simply type:
    Code:
    git init
    Now let's configure it. This is a one-time step. Check the video below at 12:30.
    Code:
    git config --global user.name 'Your Name'
    git config --global user.email 'your@email.address'
    Time to make our first backup, or in Git lingo terms, our first "commit".
    Code:
    git status
    git add *
    git status
    git commit -m 
    'Yay!! My first commit!!! Woohooo!'
    git status
    gitk

    'Note: The commands "git status" and "gitk" are not really necessary, as they're for visualization purposes only.
    Quick video tutorial (skip to 7:22):

    What is .gitignore and how to use it?
    The file ".gitignore" (yes, it starts with a dot!) is a file you can create to ignore any files you decide not to be necessary in a backup.
    This generally applies to the generated binaries.

    Usage:
    - Create an empty file named ".gitignore" in your project folder. You can use Notepad.

    File content:
    Code:
    #Git will ignore the following files/folders:
    bin/
    gen/
    src/
    *.apk
    *.dex
    *b4a.meta

    How does GitLab work?

    Once you register your new account, you'll be presented with a quick-start guide.

    If necessary, however, you may prefer to follow the instructions presented in this video:

    How do I push my commit into the online repository?
    First you'll need to add the remote repository, for example:
    Code:
    git remote add origin git@gitlab.com:username/projectname.git
    Then, it's as easy as:
    Code:
    git push origin master

    Whaaaaaaat? This is too complicated!!!!!
    Not really. Git can be a very complex system,
    but only if you decide to really dive into it.
    Stick with the basic commands and you'll be just fine. :)

    TL;DR:
    - Install Git for Windows and get an online repository.
    - Git Bash on your project folder
    - Create '.gitignore' if necessary
    - Configure Git Bash to work with your online repo.
    Code:
    git init
    git config --global user.name 
    'Your Name'
    git config --global user.email 'your@email.address'
    git remote add origin git@gitlab.com:username/projectname.git
    - Daily use:
    Code:
    git add *
    git commit -m 
    'Your message here.'
    git push origin master
     
    Last edited: Jun 22, 2017
    walterf25, Watchkido1, KZero and 25 others like this.
  2. JordiCP

    JordiCP Well-Known Member Licensed User

    Thanks!

    Related to it, really worth looking at SourceTree, a graphic (and free) Git client. I used it for a large distributed team project, and currently for some cloned github repos for my own projects. It allows to do everything from a more intuitive environmet. I think I am only using a 20% of it and it is more than enough for my daily needs (until the day in which I really break something and will need to learn the advanced command-line features).
     
    fredo, Toley, inakigarm and 3 others like this.
  3. moster67

    moster67 Expert Licensed User

    Thank you.
    I used Git for Windows some time ago but then I started copying important files to external backups instead although I much prefer gits. I will re-start using git again.

    Anyway, a good idea is also to configure the "gitignore" file if you want to avoid copying static data which are rarely changed.
    I added the following lines:

    #B4a
    bin/
    gen/
    src/
    *.apk
    *.dex
    *b4a.meta

    Another great thing with gits is that you can see changes made in code between different versions and you can also recover code-files in case you accidentally saved something you did not mean to do.
     
  4. wonder

    wonder Expert Licensed User

    Thanks!! Added!

    Yes, that's the power of Git! :)
     
    Last edited: Jun 21, 2017
  5. JakeBullet70

    JakeBullet70 Well-Known Member Licensed User

    Another good front end to GIT is Tortoisegit. It integrates in Windows explorer. But for the ones thinking about using GIT. Use it.
     
    fredo, Multiverse app and Toley like this.
  6. wimpie3

    wimpie3 Well-Known Member Licensed User

    I've used GIT already multiple times in previous projects but I've always stopped after a certain time and went back to versioned files on my NAS.

    If there is someone who deserves to be fired, it should be the programmer who invented GIT. Hard-to-use, command line based... in short: everything good software shouldn't be!

    I'm sure it is really useful when you have to work with multiple persons on the same project, but I have my doubts for single-user projects.
     
    Last edited: Jun 26, 2017
  7. MaFu

    MaFu Well-Known Member Licensed User

    I'm using Mercurial, It's more or less the same as Git (but imho the better choice on windows). And also command line based. And this is one of the best features of git and mercurial. For the normal tasks i use TortoiseHg (or TortoiseGit for Git) and never have to use the command line. But for special needs i can create batch files and automate tasks which i normally never can do with a windows only tool.
    And its not only useful for developer groups, a single user also have great benefits from a version control system.

    If a GUI is installed (like Tortoise) all tasks are very easy and mostly done with one or two mouse clicks.
     
    wonder, JakeBullet70 and JordiCP like this.
  8. wonder

    wonder Expert Licensed User

    Git was created by Linus Torvalds, you know, the guy who wrote Linux, one of the fathers of modern computing... so yeah, he should totally fire himself for designing such a tool.

    Ugh!! Typing commands into a console window, what a horrible thing to do!! Almost as horrible as having to type several lines of code just to create some stupid Android app. Who the hell does that??? Good software is all about tap-tap-click copy-paste, right? :cool:
     
    Last edited: Jun 27, 2017
  9. jimmyF

    jimmyF Active Member Licensed User

    There were two major products to come out of Berkeley: LSD and Unix. We don't believe this to be a coincidence.
    Just sayin...
    ;)
     
  10. Carlos marin

    Carlos marin Active Member Licensed User

    jordi ese sourcetree se puede trabajar con b4a tambien ???
     
  11. DonManfred

    DonManfred Expert Licensed User

    please write ENGLISH here
     
    Last edited: Sep 4, 2019
  12. Carlos marin

    Carlos marin Active Member Licensed User

    sorry, Can this sourcetree work with b4a too?
     
  13. DonManfred

    DonManfred Expert Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice