1.
Install Git:
Windows:
o Download the Git for Windows installer from the official Git website (git-
scm.com).
o Run the installer and follow the on-screen instructions. You can generally
accept the default settings.
Git --version
2. Configure Your Identity:
After installation, you need to configure your username and email address. Git uses
this information to identify your commits.
Open your terminal or command prompt and run the following commands, replacing
the example values with your own:
o git config --global user.name "Your Name"
o git config --global user.email "your.email@example.com"
o The --global option sets these configurations for all Git repositories on your
system.
3. Checking Your Configurations:
o To view your current Git configurations, use the following command:
git config --list
1. Create a GitHub Repository:
1. Click the "+" icon in the top right corner and select "New repository."
2. Give your repository a name (e.g., "my-django-project").
3. You can add a description if you like.
4. Choose whether to make the repository public or private.
5. Do not initialize the repository with a README, .gitignore, or license at this
stage. We'll handle these locally.
6. Click "Create repository."
2. Initialize a Git Repository Locally:
Open your terminal or command prompt.
Navigate to your Django project's root directory:
cd /path/to/your/django/project
Initialize a Git repository:
git init
3. Create a .gitignore File:
A .gitignore file specifies files and directories that Git should ignore. This is crucial
for excluding sensitive information and unnecessary files from your repository.
Create a .gitignore file in your project's root directory:
touch .gitignore
Open the .gitignore file in a text editor and add the following (or similar) content:
Code snippet
*.pyc
__pycache__/
db.sqlite3
/static
/media
.env
*.log
venv/
myproject/settings.py # If you have sensitive info directly in
settings.py. better to use .env
Adjust this list based on your project's specific needs. For example, if you're using a different
database or have custom log files, add them to .gitignore.
4. Add and Commit Your Files:
Add all your project files to the staging area:
git add .
Commit your changes with a descriptive message:
git commit -m "Initial commit of Django project"
5. Link the Local Repository to the Remote GitHub Repository:
Copy the remote repository URL from your GitHub repository page. It will look
something like this:
https://github.com/your-username/my-django-project.git
Add the remote repository as an origin:
git remote add origin https://github.com/your-username/my-django-
project.git
6. Push Your Code to GitHub:
Push your local commits to the remote repository:
git push -u origin master
If you're using a branch other than master (e.g., main), replace master with your branch
name. The -u flag sets the upstream branch, so you can simply use git push in the future.
7. Verify on GitHub:
Go to your GitHub repository in your web browser.
You should see your Django project files listed.
how to configure git on local machine
Configuring Git on your local machine is essential for effectively using version control.
Here's a breakdown of the key steps: