Coder Social home page Coder Social logo

git_learn's Introduction

Git and github

Git/Github tutorials can make it seem like rocket surgery. It isn't. It is very easy to set up quickly. Below I describe how. It is a kind of minimal kernel to get your repository set up locally and at github. The following assumes you have some project in a directory you want to share as a repository on github.

Set up your Git/Github accounts

Set up Git on your local machine ๐Ÿš€

a. Download and install Git (http://git-scm.com/downloads) and set it up so you can execute git commands from the terminal (Gitbash on Windows). This guide seems pretty good: https://www.atlassian.com/git/tutorials/install-git

b. From the terminal, configure your username and email:

git config --global user.name <your user name>
git config --global user.email <your email address>

Sign up your Github account

Sign up at https://github.com. For now, I recommend registering using the email you used in your Git configuration above, just to make everything simpler and easy to remember.

Turn your project into a repository

First, initialize your repository:

  1. In your project folder, make a .gitignore file that has the names of things you don't want to be version controlled (e.g., docx files, executables, pycache folders, and anything else you want hidden). You can include the wildcard character (*).
  2. cd to your project folder, and enter git init. You now have a local github repository! You pretty much are done, frankly. You can start to enter commands.
  3. git status to see what's up.
  4. git add . to add everything to staging area.
  5. git commit -m "my first commit!" to commit to repository

Now work on your project locally. When you have something cool, then commit it with the add and commit commands from lines 4 and 5. You are using git. Use git status to see what's going on in your repository. That's pretty much all I ever do locally. Use informative, short commit statements. I would recommend making a readme.md file and putting it in your project folder, as it will show up automatically nicely formatted at Github when you push (VS Code is a decent editor that lets you preview Markdown).

If you want to just add one or a few files to the staging area, just put their names instead of the period:

git add file1 file2 file3

This can be useful if you have one file that you have worked on a lot, and another that is half done and not ready to stage yet. Also, if you want to stage a bunch of files that are thematically related and commit them together, with logically individuated comments, then it is useful to do this.

Note if you make a mistake and want to remove a file from the staging area (say file3), then:

git reset HEAD -- file3

will pull it from the staging area back into the working directory.

Set up a remote repository and push your project to github

  1. At github, point and click to create repository with project name that you want (e.g., foo). The url of the repository will be provided to you (e.g., https://github.com/yourname/foo.git).

  2. Connect your local repository to the remote one using that url you just got. At your terminal:

    git remote add origin https://github.com/yourname/foo.git

  3. Push your local repository to github:

    git push origin main
    It will ask you for your remote username and pw.

Now, whenever you have finished working on your local machine and are ready for your results to show up at github, just enter that same command from step 3 and your work will be pushed to github!

Use it for a while

There, you've done it. Go check out your repository at github. Share it. Write that code! Frankly, the above is 99% of what I do with my little one-person projects. When it comes to working with larger projects, then things will get a little more complicated: you will need to learn about things like forks, branches, and pull requests. But for now, I would just focus on the above until you need to branch out.

Note if you need to clone a repository, just go to it at github, click on the green 'clone or download' icon, copy the url, and in a directory you have set up to contain the repo's folder, and type in git clone <url> where the url is the one you just copied. Now you have a local version of the repo.

Good resources โ“

Once you have messed around for a bit with the above, or need to expand into pull requests and such, the following are great resources to get started:

Then there is the online book put out by Git, which is great if you want the authoritative source with more details than the above links: https://git-scm.com/book/en/v2.

git_learn's People

Contributors

ericthomson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.