| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
some notes for git learners
Initialize a Git Project:
To start a new Git repository for your project, use the following command:
git init
Check the Status:
To view the current status of your project and its files, use:
git status
Add Files to the Staging Area:
Add files to the staging area to prepare them for commit. You have several options:
Add all files:
git add -A
Add specific file types, e.g., all HTML files:
git add "*.html"
Add specific file :
git add "file-name"
Commit Changes:
To save the staged changes as a new snapshot, use the git commit command:
git commit -m "Your message about the changes"
View Differences:
Git provides several ways to view differences:
See the difference between the current stage and the last commit:
git diff HEAD
See the difference between the current stage and the previous stage:
git diff --staged
Reset and Exit the Staging Area:
To manipulate the state of your working directory, staging area, and commit history, you can use the git reset command:
To unstage a file, use:
git reset 'filename'
To move the HEAD pointer to a specific commit and optionally modify the staging area and working directory, use:
git reset --soft <commit> git reset --mixed <commit> git reset --hard <commit>
Restore Files:
To manipulate the state of your working directory and staging area without affecting the commit history, you can use the git restore command:
To unstage a file, use:
git restore --staged <file>
To restore a specific file from a previous commit to your working directory, use:
git restore --source=<commit> <file>
To restore your entire working directory to match a specific commit, use:
git restore --source=<commit> .
Branches:
Managing branches is essential for collaboration and project organization. Here are some branch-related commands:
Show all branches in the project:
git branch
Create a new branch for your project:
git branch 'branch-name'
Delete a branch from the project:
git branch -d 'branch-name'
Checkout Branch and Files:
git checkout 'branch-name'
git checkout -- 'filename'
Merge Branches:
To merge a branch into your current branch, use:
git merge 'branch-name'
View Commit History:
To see all the commit logs, use:
git log
Remove a File:
To remove a file from Git and your project, use:
git rm 'file-name'
Push to a Remote Repository:
To push all the changes from your local master branch to a remote repository (usually in the cloud, like GitHub or GitLab), use:
git push origin master
Pull from a Remote Repository:
To update, retrieve, and replace the changes from the remote repository into your local master branch, use:
git pull origin master
Clone a Repository:
To copy an existing repository from a remote location (like GitHub) to your local machine, use:
git clone <repository_URL>
Push Changes to Remote:
To send committed changes from your local repository to the remote server, use:
git push
Add Remote Repository:
To add a remote address to your current project on your local machine, use:
git remote add origin <remote_URL>
Change Remote URL:
To replace the current remote URL with a new one, use:
git remote set-url origin <new_remote_URL>
Pull Changes from Remote:
To fetch and merge changes from the remote server into your local branch, use:
git pull origin main
Set Upstream Branch:
To track a remote branch, use:
git branch --set-upstream-to=origin/main main
Push with Upstream:
To push the current branch and set the remote as the upstream branch, use:
git push --set-upstream origin <local-branch>
Tagging:
Tags are used to mark specific points in the commit history. also you can make versions for your application
Show all tags:
git tag
Create a tag for the last commit:
git tag -a <tag-name or version-number> -m "Your message"
Create a tag for a specific commit:
git tag -a <version-number> <commit-id> -m "Your message"
Search between tags (e.g., tags starting with 'v0'):
git tag -l 'v0*'
Push a specific tag to the remote:
git push origin <tag-name>
Push all tags to the remote:
git push origin --tags
Switch to a Tag:
git switch <tag-name>
Verify your tag:
git tag -v <tag-name or version-number>
GPG Keys and Commit Signing:
Show all keys:
gpg --list-keys
Generate a new key:
gpg --gen-key
Show my secret keys:
gpg --list-secret-keys --keyid-format LONG
Set your signing key for this project:
git config user.signingKey 'your-secret-key'
Show your signing key for this project:
git config user.signingKey
Set a global signing key for all projects:
git config user.signingKey 'your-secret-key' --global
Sign your version/tag:
git tag -s 'version-number' -m "your-message"
Sign your commit:
git commit -S -m 'your-message'
Verify your tag:
git tag -v 'tag-name or version-number'
Blame History:
git blame 'filename'
git blame 'filename' -L5
Remember to use these commands as needed in your Git projects. It's important to maintain a clean and organized version control process for effective collaboration and project management.
| Back | FazBrowse Home | New Git URL |