GIT Cheat Sheet

Some basic commands and information for starting with git.
				
					#Some basic commands for starting with git:

gi๐˜ ๐—ถ๐—ป๐—ถ๐˜  

#initializes a new Git repository in your current directory.

๐—ด๐—ถ๐˜ ๐—ฐ๐—น๐—ผ๐—ป๐—ฒ <๐—ฟ๐—ฒ๐—ฝ๐—ผ> 

# clone (copy) it to the machine your working on

#๐— ๐—ฎ๐—ธ๐—ฒ ๐—–๐—ต๐—ฎ๐—ป๐—ด๐—ฒ๐˜€

๐—ด๐—ถ๐˜ ๐˜€๐˜๐—ฎ๐˜๐˜‚๐˜€ 

#It is a recommended practice to review the status of your files before or after making changes. Easily identify any modifications that have not been staged yet.

๐—ด๐—ถ๐˜ ๐—ฎ๐—ฑ๐—ฑ <๐—ณ๐—ถ๐—น๐—ฒ๐—ป๐—ฎ๐—บ๐—ฒ> 

# stage files for a commit. 

๐—ด๐—ถ๐˜ ๐—ฎ๐—ฑ๐—ฑ . 

๐—ด๐—ถ๐˜ ๐—ฎ๐—ฑ๐—ฑ -๐—” 

#add all  changed files to the stage 

๐—ด๐—ถ๐˜ ๐—ฐ๐—ผ๐—บ๐—บ๐—ถ๐˜ -๐—บ "commit message" 

#commit files with a descriptive message.

#๐—•๐—ฟ๐—ฎ๐—ป๐—ฐ๐—ต๐—ถ๐—ป๐—ด

๐—ด๐—ถ๐˜ ๐—ฏ๐—ฟ๐—ฎ๐—ป๐—ฐ๐—ต 

# list all the local branches in current repo

๐—ด๐—ถ๐˜ ๐—ฏ๐—ฟ๐—ฎ๐—ป๐—ฐ๐—ต <๐—ฏ๐—ฟ๐—ฎ๐—ป๐—ฐ๐—ต๐—ป๐—ฎ๐—บ๐—ฒ>

#create new branch

git checkout <branchname>

# Change to another branch

git merge <branchname> 

#merge changes to (usually master) main branch

#๐—ฅ๐—ฒ๐—บ๐—ผ๐˜๐—ฒ ๐—ฅ๐—ฒ๐—ฝ๐—ผ๐˜€๐—ถ๐˜๐—ผ๐—ฟ๐—ถ๐—ฒ๐˜€

git remote add origin <repo url>

๐—ด๐—ถ๐˜ ๐—ฟ๐—ฒ๐—บ๐—ผ๐˜๐—ฒ -๐˜ƒ 

#check which remote servers are connected with your local repository.

#connect to remote repo. Can also use:

git remote set-url --add <name> <url>
git remote set-url --delete <name> <url>

๐—ด๐—ถ๐˜ ๐—ฝ๐˜‚๐˜€๐—ต ๐—ผ๐—ฟ๐—ถ๐—ด๐—ถ๐—ป <๐—ฏ๐—ฟ๐—ฎ๐—ป๐—ฐ๐—ต๐—ป๐—ฎ๐—บ๐—ฒ> 

#This command sends your commits to the remote repository.

๐—ด๐—ถ๐˜ ๐—ฝ๐˜‚๐—น๐—น 

#Pull will grab and merge any changes from the remote repository.

git fetch 

#downloads changes from a remote repository without integrating them. git pull incorporates downloaded changes by merging them into the local files.

git merge 

#combines branches by creating a new commit, preserving the commit history. 

git rebase 

#moves or combines commits onto a new base

git reset 

#discards local changes completely by moving the branch pointer. 

git revert 

#undoes changes by creating a new commit that reverses the effects, preserving the commit history.

#example to add one file to repo from working machine, where git is initialized.

git add shopping_list.yml
git commit -m "new file"
git push origin main

#.gitignore: 

#The .gitignore file is used to exclude certain files and directories from being tracked by Git. 
#It uses pattern matching rules to specify what should be ignored.
#By adding filenames, extensions, or directory names to the .gitignore file, 
#you can prevent them from being committed and pushed to the repository. 
#This helps keep the repository clean and avoids including irrelevant or sensitive files in the version history.




</url></name></url></name></repo></branchname></branchname>
				
			

More To Explore