Student Summer Sprint
  • Welcome to Hackathons for Schools Student Summer Sprint!
  • Event Information
  • What is the Student Summer Sprint?
  • Useful Event Information and Links
  • Schedule
  • Our Organisers, Panelists and Mentors
    • Organisers
    • Panelists and Speakers
    • Mentors
  • Project Details
    • Themes
    • Judging Criteria and Winning Teams
    • Presentation Advice
    • Submission Checklist and FAQs
  • Coding Platform and GitLab
  • Technical Workshops
    • How to Use Git
      • Git and the Terminal
      • How to use Git - The Basics
      • Branching, Merging and Other Useful Commands
      • How to use Git - Further Resources
    • Web Development
      • HTML
      • CSS
      • JavaScript
      • Web Development - Resources
    • Introduction to Python
      • Variables
      • Data Types and String Formatting
      • Input and Output
      • Conditional Statements
      • Functions
      • Libraries
      • CHALLENGES
        • Solutions
      • Learning Python - Resources
    • Discord Bots in Python
      • Discord Bots - Resources
    • Web Scraping in Python
  • Careers Advice and Opportunities
    • University Advice
      • University Advice - Further Resources
    • CV, Applications and Interviews
      • Creating a Great CV
      • UCAS Personal Statement Advice
      • Interview Hints and Tips
      • Ultimate LinkedIn Guide
      • Applications - Further Resources
    • Different routes into a tech career
      • Different Routes into Tech - Further Resources
    • What Now?
      • More Opportunities!
Powered by GitBook
On this page
  • The Basics
  • Making changes to your code

Was this helpful?

  1. Technical Workshops
  2. How to Use Git

How to use Git - The Basics

PreviousGit and the TerminalNextBranching, Merging and Other Useful Commands

Last updated 4 years ago

Was this helpful?

The Basics

The following commands should be executed in the command prompt on your computer.

  • To start using git, you need to make sure you have it installed (you can find instructions ) and that you've signed up for a GitHub account.

  • You can create a new git repository (collection of source code files) from your own file system by navigating to the correct folder and using the command

git init
  • You can also clone a repository from the internet, by specifying the URL of the remote origin (where the files where initially downloading from)

git clone <repository-url>
  • You can set up Git with your name and email so that you'll be identified as the author for each commit

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

Making changes to your code

Assuming you're in the correct file directory, here's how you can add changes to your code to Git

  1. Add your file(s) to the staging area from the working directory. The working directory is the area you're currently working in and the changes you've made to your code on your file system. The staging area is when Git starts tracking and saving changes that occur in your files.

git add <files>

2. Commit your changes in the staging area to your local repository. This is everything in your .git directory, containing all your commits. It's the area that saves all the changes to your code. It's good practice to add a commit message which describes the changes that you've made.

git commit -m <your-commit-message>

3. Push your changes from your local repository to your remote repository. This means that your code will be viewable on GitHub and stored in the cloud. Anyone with access to your remote repository can view these changes. This command below will upload your branch to the origin, which is the remote repository you created earlier.

git push origin <branch-name>

You can update your local repository to the newest version in the remote repository using the pull command.

git pull 

The above command updates changes in your current branch. If you want to pull from a specific branch,

git pull <remote-name> <branch-name>

For example,

git pull origin master

Using git pull also merges remote changes, which could lead to merge conflicts. We'll explore this on the next page.

Congratulations - you've made a great start on the basics of using Git! There's lots more including branching, merging and other useful commands that we'll cover briefly on the next page. Make sure you check out the further resources page to get a better understanding of using Git.

here
Visual guide on Git commands, from https://dribbble.com/shots/2389144-Git-GitHub-Tutorial