GIT
In simple words, we use git to store the code of our projects. It allows us to modify the code an update it whenever required. It is a version control system. Committing new changes, branching, merging and comparing past versions are all optimized for performance.
Installation of Git
Refer this link to install Git:
CHEAT SHEET
CONFIGURATION
- Open the command line.
- Set the Username
git config --global user.name "Enter Username"
Click enter and now your Username is set.
- Set the Email
git config --global user.email "Set a valid email address"
GIT INITIALIZATION
- Create a new Repository on the Git-hub platform.
git init
- This initializes an existing directory as a Git repository.
ADD A FILE
git add (Filename)
- This adds a file. You can also put (.) instead of filename to add all the files at once.
COMMIT
git commit -m "first commit"
- This commits our files after we add them to the staging area.
STATUS
git status
- This command will show the modified status of an existing file and the file addition status of a new file, if any, that has to be committed.
BRANCH
git branch -M (Write your branch name here)
- This creates a new branch at the current commit.
REMOTE ADD
git remote add origin [URL]
Once everything is ready on our local system, we can start pushing our code to the remote repository of the project.
URL is available on the page which we get landed to, once we create the repository in Git-Hub.
- Click on the Copy icon on the right side of the URL box of the Git-Hub repository to copy the link and paste it.
PUSH
git push [alias] [branch]
Transmit local branch commits to the remote repository branch.
Suppose, we have made some changes in the file and want to push the changes to our remote repository on a particular branch. By using the command ‘git push,’ the local repository’s files can be synced with the remote repository on Git-Hub.
CHECKOUT
We use this command to navigate to an existing branch, add new files, and commit the files.
git checkout (NEWBRANCH NAME)
GIT DIFF
git diff [commit-id-of-version-x] [commit-id-of-version-y]
Diffing is a function that takes two input datasets and outputs the changes between them. The git diff command is a multi-use Git command which, when executed, runs a diff function on Git data sources. These data sources can be commits, branches, files, and more. The git diff command is often used along with the git status and git log commands to analyze the current state of our Git repository. We use git log to get the details of commit IDs.
MERGE
git merge [another-file-name]
This command will combine multiple sequences of commits into one unified history. In the most frequent use cases, git merge is used to combine two branches.
RESET
git reset –hard [SOME-COMMIT]
We use this command to return the entire working tree to the last committed state.
GIT LOG
git log
It will show the log of the branch we are in. We can check the last three logs by giving the command:
git log -3
This command is used when we want to check the log for every commit in detail in our repository.
GIT PULL
git pull origin master
The git pull command first runs ‘git fetch’ which downloads the content from the specified remote repository and then immediately updates the local repo to match the content.
CONCLUSION
This is the Git Cheat Sheet.
Thank you for reading this article. I hope it helped you in some way.