[Tutorial] Git and how to use it.

Discussion in 'Resources' started by The_Coder, Dec 4, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    The_Coder

    Hello everyone and welcome to the ultimate guild to git. So lets get into it.
    If you are looking to use a public repo then use bitbucket.

    So what is Git.
    Git is a distributed revision control and source code manager. What that means is git can track you entire project, and you can go back and look at source code before you made an error. Git also uses branches. Branches are just like other versions of your code. This is helpful so that you can keep a working copy, but you can hack on the other version to your hearts content.

    How to get Git.
    Now that you know how awesome Git is you are probably saying to yourself how do I use this. Well you are going to need to download it from here. Once installed on windows 7 or 8 search for Git Bash in your programs. Open that up because we are going to need it for the next step.

    How to use it.
    Git may seem very hard at first but you will get the hag of it soon. First thing that you need to use git is setup. Navigate to your preferred dir. This is where you want git to track your files. So if you had a workspace folder and then your projects in side that. You want to have a git instance for each of your projects that you have. Use the command: cd /path/to/project. Once you get there use the simple command: git init. Congratulations! You have setup git in that folder. If you use git status it should show you all of the files in there.
    Now we have to add files to git. There are some files that people would not care to have in there public repo online and there is really no need to track some files. That is where a special file comes in handy. It is called the .gitinore. This file you can list files or file types and even folders.
    Example:
    Code:
    # Eclipse stuff
    .classpath
    .project
    .settings/
     
    # netbeans
    nbproject
     
    # maven
    /*/target/
    target/
     
    # gradle
    .gradle/
     
    # vim
    .*.sw[a-p]
     
    # various other potential build files
    /*/build/
    /buildassets/map_*.txt
    /*/bin/
    /*/dist/
    /*/manifest.mf
    /release
     
    # Mac filesystem dust
    .DS_Store
     
    # intellij
    *.iml
    *.ipr
    *.iws
    .idea/
     
    .checkstyle
     
    # Testfiles
    test.sh
    If you create this file .gitignore with the example all of those files, file types, or folders will not be tracked by git. Now lets add the files. There are two ways of doing this: "git add <filename>" or you could do: "git add ." Don't forget the period that tells git to track all of the untracked files.
    Just because the files are added doesn't mean that they are snapshot by git also called commit. Committing is very easy. First lets see if git has started tracking all of our files. Execute the command: git status. If there are a bunch of green files and git says that there is something to commit, then just type: "git commit -m 'Add a commit message here'". You just created a commit.

    Will be continued...
    (Coming soon branches and merging)

    Some basic commands:
    Code:java
    1. git
    2. //This is the base command (you will be using this one a lot)


    Arguments for the command git:

    Code:java
    1. git add //Add file(s) to be tracked by git
    2. ------------------------------------------
    3. git branch //Command to list, add, or delete branches
    4. git branch <NameOfNewBranch> //Creates a branch
    5. git branch -D <NameOfBranch> //Deletes a branch
    6. ------------------------------------------
    7. git checkout //Command to look at a branch
    8. git checkout <NameOfBranch> //Which branch is the head
    9. ------------------------------------------
    10. git clone //Clones a repo
    11. git clone <repo>
    12. ------------------------------------------
    13. git commit //Commits changes to files in git
    14. git commit -m "Message" //Commits with a message
    15. ------------------------------------------
    16. git diff //Can compare commits, branches
    17. git diff <branch> <branch> //Compares two branches
    18. ------------------------------------------
    19. git init //Creates a blank repo
    20. ------------------------------------------
    21. git log //Shows the log of commits on the current branch
    22. ------------------------------------------
    23. git merge //Merges two branches together
    24. ------------------------------------------
    25. git push //Pushes the current branch to remote repo
    26. ------------------------------------------
    27. git rebase
    28. ------------------------------------------
    29. git status //Checks if any files aren't being tracked by git[/syntax=java]
    30.  
    31. (Place holder)
    32.  
    33. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
    AnUnknownMiner and MCCoding like this.
  2. Offline

    Ultimate_n00b

    I find it simpler to use Github and their Mac/Windows client.
     
    Minecrell likes this.
  3. Offline

    malandrix_bunny

    Me too, but github isnt a favorite for everyone.
     
  4. Offline

    The_Coder

    BitBucket is awesome
     
  5. Offline

    NoChanceSD

    TortoiseGit is also really easy to use, but never used anything else so probably not the best option out there.
     
Thread Status:
Not open for further replies.

Share This Page