If you like saving your future self from pain then learning these few Git moves is a good investment. This guide walks you through creating a local Git repository with git init
connecting it to a GitHub remote making your first commit and pushing it up so other humans can stare at your code.
What we will do
Short version for busy developers who want results not drama
- Initialize a local repository with
git init
- Create a repository on GitHub to act as the remote
- Link the local repo to the remote with
git remote add origin
- Stage files commit them and push with
git push
- Use a Git GUI if you prefer pretty clicks to cryptic lines
Initialize a local repository
Open a terminal in your project folder then run
git init .
git status
The first command makes the folder a Git repository and the second shows untracked files. If you see a pile of files you did not expect add a .gitignore
before committing so you do not accidentally version your secrets or build artifacts.
Create the remote on GitHub
On the GitHub website click New repository choose a name and optional README. That creates a remote endpoint for your project. Copy the repository URL shown on the page for the next step.
Connect the local repo to the remote and confirm
Link the local repository to the GitHub repository with a command like
git remote add origin <repository URL>
git remote -v
Use the URL shown on the new repository page instead of the placeholder. git remote -v
shows the remotes and the fetch and push URLs so you can confirm you did not type garbage.
Make the first commit and push it to GitHub
Stage files then create a snapshot with a short descriptive message
git add .
git commit -m "Initial commit"
Upload the commit to GitHub with
git push -u origin main
If your default branch is named master
replace main
with master
. The -u
flag sets upstream so future pushes are shorter and quieter.
Use Git GUI tools when you need to see pretty diffs
GUI clients like GitHub Desktop and others show diffs staging and branches with clicks instead of typing. They are useful for visual work and for people who do not worship the terminal every hour of the day.
- Stage and unstage files with a click
- View branch graphs and history visually
- Resolve simple merge conflicts with a guided interface
Troubleshooting tips for common annoyances
- If push fails check that your local branch name matches the remote branch name
- If authentication fails use a personal access token or SSH key rather than a password
- If you forget to add files you can amend the last commit with
git add
thengit commit --amend
- Use
git log --oneline --graph --all
to visually inspect your commit history
This guide covered the essentials for initializing a repository with git init
creating a GitHub remote linking the two making your first commit pushing to the remote and using GUIs when the need for visual help arises. Follow these commands and you will be version controlling like a slightly smug professional in no time.