Thread: Git: What it is, how to use it, and why it will improve your server

Page 1 of 4 123 ... LastLast
Results 1 to 10 of 40
  1. #1 Git: What it is, how to use it, and why it will improve your server 


    Major's Avatar
    Join Date
    Jan 2011
    Posts
    2,997
    Thanks given
    1,293
    Thanks received
    3,556
    Rep Power
    5000
    Quote Originally Posted by Wikipedia
    Git is a distributed revision control and source code management system with an emphasis on speed. Git is open source.
    This means:
    • It's fast (duh).
    • It's free.
    • It tracks your code changes.
    • It's easy to rollback if you find a bug.
    • No accidentally overwriting work your friend did.


    Related - The Benefits of Open Source:
    • Other people can help and chip in. Free code (and help) for nothing!
    • Bug reporting and fixing becomes a lot easier.
    • Improve your community - people team up to help, work together, and fix problems.
    • Lets people see you are updating and working on it all the time.


    There is no good reason not to use a proper version control system for your code. Just because it has a long name doesn't make you incapable of using it. It is incredibly simple if you spend literally 5-10 minutes to understand the basics.

    PSA: Git is not GitHub

    GitHub is a hosting service for git repositories (code projects). You can use GitHub with git. They are not the same.




    This is Octocat, the lovable GitHub mascot.


    This is git, with a less impressive logo.




    Installing Git:

    Go to the git downloads page here. Download the release appropriate for your operating system. Install it.

    Creating a GitHub (or other) account:
    GitHub offers free project hosting for open source projects and I highly recommend it. BitBucket offers free project hosting for both open and closed source projects, and is another good one. This guide will use GitHub because I want you to open source your code. If you'd rather use BitBucket, the gist is the same as this.

    1. Go to GitHub. Pick a username and password, and supply a working email. Tuh-dah.

    Setting your username and email:

    You set this so git knows who made the commit.
    1. Make a folder to keep your project code in (or use an existing folder).
    2. Open Git Bash in this directory (can right click in explorer.exe and select Git Bash if you're on windows).
    3. Type the following:


    Code:
    git config --global user.name "Your Name Here"
    Code:
    git config --global user.email "[email protected]"
    If you want to use a different username or email for each project, drop the "--global".

    Letting git use your local folder (the code on your computer):

    1. Go to the folder.
    2. Open Git Bash.
    3. Type "git init".


    Explanation of terminology:

    • Upstream Repository: The version of your project that's on the internet (i.e. on GitHub, BitBucket, etc)
    • Local Repository: The version of your project that's on your computer.
    • Commit: Telling your local repository that you've updated a file (or files), and to use the updated one instead.
    • Index: Where git stores local commits that haven't been sent to the upstream repository.
    • Push: Updating the code in the upstream repository with (updated) code from your local repository.



    Ignoring unnecessary files:

    There are some files that you don't want to push to git. This can because they contain secure information (like your SQL database user/password), or because they're unnecessary for other people (like your compiled files - .class etc). Luckily, git makes it easy to auto-ignore these - using a file called .gitignore. You add every path (i.e. folder), file, or file type you don't want git to upload, and it'll ignore those by default (you can override this when committing if you wish).

    Here's one I prepared earlier:

    Code:
    !.gitignore
    .*
    *~
    /target
    *.iml
    /lib
    /bin
    Generally it's bad to upload any settings files (like .project that eclipse generates), any libraries (such as netty), or any compiled files (.class etc). Also note that if you have a class that contains SQL user/database information (you should read it from a file at startup instead) you can't just leave that class out - you'll have to do what i suggest (hint) or edit the file every time you commit it (which is going to get annoying very quickly).

    Linking your local repository with an upstream repository:
    (Remember, this means linking the code on your computer to the code on GitHub)

    1. Go to the new repository page on GitHub (here).
    2. Name and describe it
    3. Hit 'Create Repository' (you should've already run "git init", so don't check that box).
    4. Copy the HTTP URL from the next page (i.e. from this box).
    5. Now open Git Bash in your local repository (the folder you used before) and type:


    Code:
    git remote add origin PASTE_YOUR_URL_HERE
    And then:

    Code:
    touch README
    git add README
    git commit -m "First commit"
    git push -u origin master
    Your code is now on GitHub. Nice one!

    Committing updated files:
    So you've written new code. Now what? Luckily, this can be dealt with in about 5 seconds.

    • Open Git Bash in your local repository.
    • Type the following (you can use *.java to add every java file - it'll only include the ones that you've changed).


    Code:
    git add FILE_NAME_HERE
    • Type the following - the commit message requires " " and you should be speaking to git like you're ordering it around (e.g. "Add file x", "Fix bug something", etc).

    Code:
    git commit -m "COMMIT MESSAGE HERE"
    Updating upstream repositories:
    Made a commit? Great, now you can update the upstream repository (e.g. your GitHub repository) with one simple command:

    Code:
    git push
    Your repository host (e.g. GitHub, BitBucket) will ask for your username and password so that random people can't update your code, and you're done!

    Useful guides and links:
    NDP Software Git Cheatsheet.
    Salesforce Cheatsheet.
    GitHub help.

    Didn't think this was useful enough? Try Git online.
    Video learner? Check this out (80 minutes).


    Looking for more? Check out the free Pro Git book.
    Reply With Quote  
     


  2. #2  
    Project Drop-Zone Owner & The BLOOD Gang Always Banging RED


    Join Date
    May 2013
    Age
    28
    Posts
    2,992
    Thanks given
    5
    Thanks received
    937
    Rep Power
    183
    Such a quality thread. Plus its a lot better then using dropbox to work as a team lmao


    Thanks for posting this so it gets used more often around here. Don't often see many people using it. Now get back to work on that Apollo haha
    Reply With Quote  
     

  3. #3  


    Major's Avatar
    Join Date
    Jan 2011
    Posts
    2,997
    Thanks given
    1,293
    Thanks received
    3,556
    Rep Power
    5000
    Quote Originally Posted by Jane And Finch View Post
    Such a quality thread. Plus its a lot better then using dropbox to work as a team lmao
    Dropbox is ideal for sharing something that git (more specifically, patch and diff) are not designed for - images (e.g. if you design graphics with others) spring to mind here. But you're right, it's really, really not suitable for code.
    Reply With Quote  
     

  4. #4  
    Registered Member

    Join Date
    Aug 2007
    Posts
    1,289
    Thanks given
    130
    Thanks received
    340
    Rep Power
    862
    Hope this gets people to start using git instead of dropbox. It really is way better.
    Reply With Quote  
     

  5. #5  
    Head Veteran and Respected Member


    Thakiller's Avatar
    Join Date
    Dec 2006
    Age
    26
    Posts
    2,953
    Thanks given
    1,957
    Thanks received
    3,074
    Rep Power
    5000
    You must spread some Reputation around before giving it to Major again.
    Reply With Quote  
     

  6. #6  
    Registered Member

    Join Date
    Oct 2011
    Age
    28
    Posts
    1,880
    Thanks given
    311
    Thanks received
    557
    Rep Power
    703
    This is really good especially for those who need to keep a local copy of their source and one on their VPS in sync
    Reply With Quote  
     

  7. Thankful users:


  8. #7  
    Registered Member
    Join Date
    Sep 2013
    Posts
    105
    Thanks given
    13
    Thanks received
    28
    Rep Power
    10
    I personally prefer using svn.
    Reply With Quote  
     

  9. #8  
    Banned Git: What it is, how to use it, and why it will improve your server Market Banned


    Join Date
    Jan 2011
    Age
    26
    Posts
    3,112
    Thanks given
    1,198
    Thanks received
    1,479
    Rep Power
    0
    Took me awhile to start using version control and get used to it but I'm so glad I did. It saved my ass when my computer crashed and I had lost all of my other files.
    Reply With Quote  
     

  10. Thankful user:


  11. #9  
    Donator
    Ashley's Avatar
    Join Date
    Oct 2011
    Age
    29
    Posts
    411
    Thanks given
    175
    Thanks received
    70
    Rep Power
    67
    Thanks for this, I didn't realize what you could do with git which I why I never really used it. Next project I make I'll most likely use git.
    Reply With Quote  
     

  12. #10  
    JavaScript Heathen 👹

    frostbit3's Avatar
    Join Date
    Mar 2012
    Age
    29
    Posts
    404
    Thanks given
    381
    Thanks received
    90
    Rep Power
    78
    10/10 would read again. Already using git, but still .
    >> real life is pretty much the same as code. off-by-one, naming, and unterminated recursion
    Reply With Quote  
     

Page 1 of 4 123 ... LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. How to use PDO and how to not suck at everything (ever)
    By Orpheus in forum Website Development
    Replies: 11
    Last Post: 07-03-2013, 04:55 PM
  2. what base is best to use?
    By Ep1k in forum Help
    Replies: 5
    Last Post: 06-01-2012, 05:22 PM
  3. How to use Switches and Cases
    By Lemonslayor in forum Website Development
    Replies: 7
    Last Post: 03-12-2010, 05:41 AM
  4. How to use (cmd[4]) IF it's stated?
    By Iceman in forum Help
    Replies: 1
    Last Post: 01-27-2009, 08:37 AM
  5. How to add the NEW similer 2H emote on your server!
    By dragonxqx1 in forum Tutorials
    Replies: 19
    Last Post: 07-27-2008, 04:40 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •