Git - A version controller system for programming
Git isĀ a distributed version control system that tracks changes in any set of computer files, usually used for coordinating work among programmers wikipedia
Install
From: https://git-scm.com/
Git basic commands
Go to your prooject folder and, then, initialize a repo with
Once you do that, you will see a .git folder in your project folder.
git status
This tells you what it is not still saved in the repository. These are the "untrack" files.
git add
"Git add" add changed files/folders to the repository staging area of the branch. It tracks them. You can add a single file with:
You can also add a folder
You can add all unstaged files with a dot:git rm --cached
You can unstage files from being commited
git commit
Commit the changes you have staged properly with:
To undo the most recent commit we've made:
git config
To setup user name and user email:
git branch
To create a new branch:
To list all existing branches:
To switch to a branch:
To create a new branch and checkout into it in one command:
To delete a branch:If you want to force the deletion (maybe some changes are not staged), then:
git merge
Having two branches (main and newbranch), to merge changes contained in newbranch to main branch, go to main branch with "git checkout main" and merge the new branch with:
git log
It displays all commits and their commit message. Every commit has an id associated. Yo can use that id for reverting changes.
git revert
It allows us to revert back to a previous version of our project.
.gitignore
It's a configuration file that allows you to hide existing files and folders in your repository. Content listed there don't get pushed to a public repository. The file is called .gitignore and has one line per resource to be ignored.
Also, important, if a file was staged before you will need to remove it from cache...
git remove --cached
To remove from cached files and include it later into the .gitignore file list.
git remote
To check out which remote repository our local repository is connected to:
To connect my local project folder to the github repo.
git push
To push our local changes into the connected github repo:
Note: origin references the connection, and main is because we are in the main branch (that's what we are pushing). The first git push is a little different from future gitpushes, since we'll need to use the -u gflag in order to set origin as the defaulto remote repository so we won't have to provide its name every time.Some tricks
Counting commits
If you want to specify a branch name:Backing-up untracked files
Git, along with some Bash command piping, makes it easy to create a zip archive for your untracked files.
Viewing a file of another branch
Sometimes you want to view the content of the file from another branch. It's possible with a simple Git command, and without actually switching your branch.
Suppose you have a file called README.md, and it's in the main branch. You're working on a branch called dev: git show main:README.md
Pentesting git
Source: https://thecyberpunker.com/tools/git-exposed-pentesting-git-tools/
git-dumper
https://github.com/arthaud/git-dumper
Last update: 2024-05-03 Created: January 1, 2023 21:59:36