






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
It's a cheat sheet for every GitHub user
Typology: Cheat Sheet
1 / 11
This page cannot be seen from the preview
Don't miss anything!
$ git config --global user.name “
Git now knows that it should watch the folder you initiated it on. Git creates a hidden folder to keep track of changes. $ git init
$ git add
$ git add --all $ git add - A
Staged files are files that are ready to be committed to the repository you are working on. When you first add files to an empty repository, they are all untracked. To get Git to track them, you need to stage them, or add them to the staging environment.
If you are having trouble remembering commands or options for commands, you can use Git help. $ git
In Git, a branch is a new/separate version of the main repository. Branches allow you to work on different parts of a project without impacting the main branch. When the work is complete, a branch can be merged with the main project. We can even switch between branches and work on different projects without them interfering with each other.
$ git branch
$ git branch
$ git checkout
$ git checkout - b
$ git branch - d
$ git merge
Copy the url or the link of the repo that we just created. As an example, it should look like this - https://github.com/durgeshm /example.git Paste the copied url in the below git command. $ git remote add origin
First commit all the changes. Then push all the changes to our remote origin i.e. remote repo on github. $ git push origin
Git pull is used to pull all changes from a remote repository into the branch we are working on. It is a combination of fetch and merge. Use it to update your local Git. $ git pull origin
First, check which branches we have and where are we working at the moment by ‘git branch’ command. Since we do not have the new branch on out local Git which is to be pulled from the Github. So, to see all local and remote branches, use - $ git branch - a
$ git branch - r Now, the new branch is seen in the console but it is not available on our local repo. So, let’s check it out using ‘git checkout
First, let’s create a new local branch which we will be pushing to Github. Enter the command as ‘git checkout - b
We can clone a forked repo from Github on our local repo. A clone is a full copy of a repository, including all logging and versions of files. Move back to the original repository, and click the green "Code" button to get the URL to clone. Copy the URL.
‘revert’ is the command we use when we want to take a previous commit and add it as a new commit, keeping the log intact. First thing, we need to find the point we want to return to. To do that, we need to go through the log. To avoid the very long log list, use the --oneline option which gives just one line per commit showing – i. The first seven characters of the commit hash ii. The commit message
We revert the latest commit using ‘git revert HEAD’ (revert the latest change, and then commit). By adding the option --no-edit, we can skip the commit message editor (getting the default revert message). $ git revert HEAD --no-edit
To revert to earlier commits, use ‘git revert HEAD~x’ (x being a number. 1 going back one more, 2 going back two more, etc.)
‘reset’ is the command we use when we want to move the repository back to a previous commit, discarding any changes made after that commit. First, get the seven characters of the commit hash from the log for the commit that you want to go back for. Then we reset our repository back to that specific commit using ‘git reset commithash’ (commithash being the first 7 characters of the commit hash we found in the log).
$ git reset
Even though the commits are no longer showing up in the log, it is not removed from Git. If we know the commit hash, we can reset to it using ‘git reset
commit --amend is used to modify the most recent commit. It combines changes in the staging environment with the latest commit, and creates a new commit. This new commit replaces the latest commit entirely. One of the simplest things you can do with --amend is to change a commit message. $ git commit --amend - m “
Adding files with --amend works the same way as above. Just add them to the staging environment before committing.