Understanding Git Architecture
Git operates with a distributed architecture consisting of remote repositories and local copies. Each remote repository typically represents a project, containing multiple branches. The term "origin" refers to a pointer to a specific remote repository, while "master" denotes the default branch pointer on both remote and local systems.
Remote vs Local Structure
On the remote server, repositories contain various branches with "master" being the primary branch pointer. Locally, "master" points to the branch copy retrieved from the remote server.
Basic Git Workflow
Git utilizes a staging area to prepare changes for commitment:
git addmoves files to the staged stategit commitmoves staged files to the committed state- Use
git commit -m "message"to include commit messages
Push Command Syntax
The push operation follows this pattern: git push REMOTE LOCAL_BRANCH:REMOTE_BRANCH
When local and remote branch names match, the command simplifies to: git push REMOTE BRANCH
Example: git push origin master:master becomes git push origin master
Repository Configurasion
Check current configuration:
git config user.name
git config user.email
Global Git Settings
Configure global user stetings:
git config --global user.name "YourUsername"
git config --global user.email "your.email@example.com"
git config --global credential.helper store
Creating a New Repository
Initialize and set up a new Git repository:
mkdir project-directory
cd project-directory
git init
touch README.md
git add README.md
git commit -m "Initial commit"
git remote add origin https://repository.url/path.git
git push -u origin master
Troubleshooting Push Errors
When encounetring push ref errors due to repository inconsistencies:
git pull --rebase origin master
git push -u origin master
This synchronizes remote changes before attempting to push local commits.