Install git using your package manager eg. sudo apt install git
.
Open a terminal and type git
.
If you get a prompt to install xcode command line tools, let it install.
If you're impatient or want the latest version, you can install Git with this download
You may need to follow this guide if you use the second option.
You'll have to download Git and a Terminal from here.
- Keep a history of your work
- Undo bad changes
- Work on the same project with others
- Backup your code to the internet
- Try risky ideas
Short answer: anything!
Longer answer: Anything that is in a plain-text format (source code, text files, html) can be tracked by Git very well. Binary files also can be tracked, but you shouldn't put certain binary files into Git. You shouldn't add generated executable files and object-code (.class, .pyc) because those files can be built using the source code. Images are generally okay to add, GitHub will even show the differences in images!
We need to tell git who you are first.
Type git config --global user.email "[email protected]"
to set your email.
Then type git config --global user.name "Johnny Hacker"
to set your name.
In your terminal type mkdir myproject
and cd myproject
to create and enter a project directory.
To make your current directory a git repository, just type git init
.
Now that you have a directory with git, you can use the directory just like any other directory.
Write or copy some files into the directory, and then type git status
.
This will show you the current status of what's available to add to Git.
Under untracked files, you'll see the files that are in the directory, but not stored in Git.
To start tracking a file, type git add myfile.txt
.
This hasn't saved the changes yet because we need to ask git to do that first.
Add any other files with git add otherfile.txt coolpicture.jpg etc.
.
When you're ready to save your changes, type git status
to review what's going to be saved.
If it all looks good, type git commit -m "Write something descriptive here"
.
To see what was saved, type git show
. If you want to see a log of all of your previous commits, type git log
.
Now that you have a git repository on your computer, you might want to back it up somewhere safe. By uploading your git repository to GitHub, you'll let other people see what you're working on and allow others to help you make an awesome project. You'll need a GitHub account to do this. Make sure you use the same email that you configured git with when you join.
Make sure Initialize this repository is unchecked! Since you already made the repo locally, we want to start with an empty repo.
You'll be prompted for your GitHub username and password so that they know it's you.
After running git push -u origin master
, your code should be on GitHub!
If you make more changes, you can run git push
after committing your files to send the changes to GitHub.