-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathgit_notes.txt
More file actions
47 lines (39 loc) · 2.64 KB
/
git_notes.txt
File metadata and controls
47 lines (39 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
## Most common commands:
git init
git add . -> it will add all the changes and files to the staging phase.
git add <filename> -> it will add all the changes in the filename or add a new filename
git commit -m "my first commit"
git remote add origin http://github... -> remote repository URL
git remote -v -> Verifies the new remote URL
git push origin main
git merge <branchname> -> It will merge the branch name in to the main branch. (you need to be on the main branch)
git status -> Returns a list of files in the local project and if the have been added, commited or not.
git checkout <hash of a previous commit> -> this goes back in the timeline to a previos commit.
git branch -> it will list all the branches and indicate the current branch you are in.
git checkout <name of existing branch> -> it switch to another (existing) branch
git checkout -b <new branch name>. -> this will create a new branch
git --force origin <branch name> -> it will overwrite all code in remote repo (including if others commited changes)
git --force-with-lease origin <branch name> -> safer option. I will not overwrite commits other memebers did
git clone -b <branch name> git@github.com:user/myproject.git -> this will clone a specific branch
git fetch origin main. -> download all latest changes from remote repo, it doesn't merge those changes into your local branches.
git pull -> is like git fetch, but it also merges remote changes into your local branch directly.
git fetch origin main
## Reseting git:
git checkout --[filename] -> brings back last version from the cloud, discards local version.
git fetch origin -> brings all documents from branch on the cloud, dirregards local files.
git reset --hard origin/master -> discards all local changes.
#Most of all other commands:
git init -> It initializes git in the local folder in the computer
git config --global user.name "Marco" -> It configures git
git config --global user.email
git clone http://... -> It clones a repository to the local folder in the PC.
git add . -> Add all changes and files to the local git
git commit -m "new changes fixed" -> commits changes to local git and adds the comment
git status -> It tells you what branch you are in
git push origin branchname -> pushes changes to the cloud to the branchname
git push origin main -> pushes to the main branch
git merge [branch_name] -> merge branch_name to main branch. *Make sure to be on the master git branch.
git log -> Shows a log of the whole history of the changes
git log --author=marco -> Shows logs of the username
git log --pretty=oneline -> Shows logs in one line description (short version)
git log -help -> gives all options for log and help