Beginner’s Guide to Git: Getting Started and Using GitHub Desktop
What is Git?
Git is a distributed version control system used for tracking changes in source code during software development. It allows multiple developers to collaborate on projects, manage revisions, and track changes over time.
Getting Started with Git
1. Install Git
- Visit the official Git website at git-scm.com to download the latest version of Git for your operating system.
- Follow the installation instructions provided on the website to install Git on your computer.
2. Set Up Git Locally (Optional)
- If you prefer to set up Git configurations locally for each repository:
- After installing Git, navigate to your repository directory in the terminal or command prompt.
- Set your Git username and email address locally using the following commands:
git config user.name "Your Name"
git config user.email "[email protected]"
- These configurations will apply only to the current repository, you can use the global parameter to make it system wide:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
About global and local
Global configurations are available for the current user for all the projects and stored in:
~/.gitconfig or ~/.config/git/config
i.e. C:/Users/Username/.gitconfig
Local configurations are available for the current repository only and stored in:
[repository]/.git/config
i.e. C:/Users/MyProject/.git/config
3. Create a GitHub Account (Optional)
- GitHub is a popular platform for hosting Git repositories and collaborating with others on projects.
- Visit github.com and sign up for a free account if you don’t already have one.
4. Initialize a Git Repository
- Navigate to the directory where you want to start tracking changes with Git.
- Use the following command to initialize a new Git repository:
git init
5. Add and Commit Changes
- Add files to the staging area using the
git add
command:
git add filename
- Commit changes to the repository using the
git commit
command:
git commit -m "Commit message"
6. View Repository History
- Use the
git log
command to view the commit history of the repository, you can also usegit log --oneline
for a prettier/concise output.
Using GitHub Desktop
GitHub Desktop is a user-friendly application that simplifies the process of working with Git repositories.
1. Download GitHub Desktop
- Visit the GitHub Desktop website at desktop.github.com and download the application for your operating system.
- Follow the installation instructions to install GitHub Desktop on your computer.
2. Sign in to GitHub Desktop
- Launch GitHub Desktop and sign in with your GitHub account credentials if you have one. If not, you can use GitHub Desktop without signing in.
3. Clone a Repository
- To clone an existing repository from GitHub, click on the "File" menu and select "Clone Repository."
- Choose the repository you want to clone from the list or enter the repository URL.
4. Create a New Repository
- To create a new repository, click on the "+" icon in the upper left corner and select "Create New Repository."
- Follow the prompts to set up your new repository and add files.
5. Commit Changes
- After making changes to your files, you can commit them using GitHub Desktop.
- Add a summary and description of your changes, then click the "Commit to main" button.
6. Sync Changes
- To sync your changes with the remote repository on GitHub, click on the "Sync" button in the upper right corner.
Additional Resources
- Visit the official Git documentation at git-scm.com/doc for comprehensive guides, tutorials, and references.
- Explore GitHub’s official guides and documentation at docs.github.com for more information on using GitHub and collaborating with others.
- Check out how to ignore files.