Get the list of untracked files and unstaged commits

Remove a Git commit before a push

Undo commit and keep all files staged: git reset --soft HEAD~Undo commit and unstage all files: git reset HEAD~Undo the commit and completely remove all changes: git reset --hard HEAD~

Remove directory from git and local

git rm -r one-of-the-directories // This deletes from filesystem
git commit . -m "Remove duplicated directory"
git push origin <your-git-branch> (typically 'master', but not always)

Open Git UI window

gitk

How to create a new branch?

git branch newBranchName

Get the list of branch

git branch

How to switch branch

git checkout branch-name

How to create a new branch and switch to it at the same time

git checkout -b branch-name

How to merge a branch to master and then delete it

git branch -D branchName//if u use lowercase d, git will ask u first to merge

Adds all the untracked files

git add -A

but if you want to be sure no additional files are added, just give an -n parameter as well

git add -A -n

Update local repo

See all new commits

Crate local Repo

git initgit .addgit commit

Create GitHub Repo

Make sure you don’t add lisence or readme when you create the repo from github otherwise it will give an error on pushing commits Updates were rejected because the remote contains work that you do not have locally.

git remote add origin https://github.com/cubeton/mynewrepository.gitgit pull origin master  //if you already have something uploadedgit add.git commit -amgit push -u origin master

Ignore Files

apps
client
.env
node_modules

To push changes onto a new branch on GitHub, you’ll want to run git push origin yourbranchname.

after that changes can be merged into the main branch

What is origin?

Pull Request

This is what the PR page looks like before you’ve submitted it:

Merging

Note that this button won’t always be green. In some cases it’ll be grey, which means you’re faced with a merge conflict. This is when there is a change in one file that conflicts with a change in another file and git can’t figure out which version to use. You’ll have to manually go in and tell git which version to use.

When you are done, it’s best to delete the branch

Working with Git remotes and pushing to multiple Git repositories

You can have as many remotes as you want, but you can only have one remote named “origin”. The remote called “origin” is not special in any way, except that it is the default remote created by Git when you clone an existing repository. You can configure a second remote, push to/pull from that remote, and setup some branches to track branches from that remote instead of origin.

Try adding a remote called “github” instead:

$ git remote add github https://github.com/Company_Name/repository_name.git# push master to github
$ git push github master
# Push my-branch to github and set it to track github/my-branch
$ git push -u github my-branch
# Make some existing branch track github instead of origin
$ git branch --set-upstream other-branch github/other-branch

Obviously the added files will be the same

Or you can make origin push to more than one git repository server at a time. (I don’t recommend as the earlier method has more control)

git remote set-url --add origin ssh://git@bitbucket.org/user/myproject.git

To Get list of remotes

git remote

How to Fix `Updates were rejected because the remote contains work that you do`

git push -f origin master

To change url of remote

git remote set-url origin ssh://git@bitbucket.org/user/myproject.git

we just skipped--add

Instead of ‘origin’ you can uses your own remote name

Resources

https://product.hubspot.com/blog/git-and-github-tutorial-for-beginners

Finding Magic.