Wow, thank you! The problem is that the terminal app gets stuck at git add. It seems like I have a lot of files in my laptop and it seems to be adding everything that I have to the repository instead of choosing particular ones. Am I doing something wrong?
Nevermind, I finally got it
Git and GitHub are only intimidating until you start using them, once you do they make a lot of sense!
Yes, you have to know it.
No, you are not stupid for having trouble with it. It is a little confusing at first. And even once you get past the first stages of pushing and pulling and such, the workflow of branching and merging with multiple people working can be confusing, even when experienced. Just keep at it and you’ll get it.
I am sure anyone who has ever learnt Git has had the same feeling about it - Its confusing.
But here is a tutorial I used to learn all I needed to know. Take a day and go through it and you will be fine.
I still refer to this tutorial when I get stuck or if forget something.
Hope this helps!
I will throw in my 2-cents on this because I feel the most important fact has not been mentioned yet:
If you’re the sole programmer, on a closed source system, no of course you don’t need to know GIT. So one might think, why even bother, my code isn’t being shared ?
Well for one, even if it is in a private repo, if you utilize the GIT methodology it is like having and endless ‘undo’ button on your own code. Normally the Alt-Z privileged dies when the app is closed or the computer turned off. Not so with a properly maintained repository. Even I kind of learned again the deep advantages of this recently as FCC has decided to store student code in the browser cache, and not knowing this I had to reset it. I never ‘cheated’ on the early assignments and from then on on the harder challenges is preserved… But imagine losing all your code.
But, once you accept and become part of a member of a team, not only is your coding position strengthened by your teammates… It also can become a lot more complicated.
So a GIT is not ‘just’ about ‘back-tracking’, it is also about sharing and deciding, as a team, what additions might be fruitful and which may not-- (what ‘fork/push’ is about in a repository) Essentially the core of Agile development and at least what I see as the Scrum-- I actually did play rugby in high school, though we were denied official funds as being ‘too violent’ and had to door-to-door to collect for our ‘club’— I’ve never yet or since played in such a ‘team sport’-- No heros, it doesn’t work like that, it is a ‘team effort’.
So to put it briefly, and maybe just for one’s ‘own’ code-- infinite ‘instant replay’ ? ‘Yes please–’
For working with teams, a democratized means for additions + sharing + backtracking even if an idea is good but doesn’t quite work out-- Also excellent.
Someone else tell me if I am wrong, but this is what GIT means to me.
Knowing any VCS/SCM will do, git is just one of the most popular ones.
You can also look into tools such as Git Kraken that make the experience of Git more visual than command line code. It helps to understand the commands and all, but for a visual person like me a GUI Git tool is a life saver.
If you are having problems understanding git itself, I liked the following free online book hosted at the git website https://git-scm.com/book/en/v2. You won’t need to read everything because of how thorough it is. Despite being thorough, It’s still an easier read, and I actually enjoyed it.
Don’t get too down on yourself, it took me quite a while to get git and I’m still learning (and I have 20 years of software development with multiple version control systems). Git is very, very powerful, but as a consequence it does things in ways that are not initially intuitive, simple or even like most of the other version control systems. It sounds to me like you are coming along just fine.
Two bits of advice for what it’s worth. First, always use the command line git commands whenever you can. All of the documentation refers to these commands, and they are the most powerful. The GUIs work, but I think you’ll learn more at the command line. Second, make sure to use git for all your projects and work. Get in the habit of always checking in (and pushing if you are using a server) on a daily basis. Repetition by making it part of your work habit is key.
I would recommend experimenting with just git (minus connecting it to github) using a good GUI for it (I like gitkraken). Make a folder/repo, add a text file, then practice making changes, staging them, committing them, resetting them, etc. That’s how I learned to understand how it works (how it diffs the files and keeps a log, etc). I still keep a practice folder around for testing more advanced commands. Over time I moved to just doing the simple stuff over the command line because it’s faster because I often have it open already (and now Visual Studio Code because it integrates so well with it).
Also once you do feel comfortable enough to start using it with projects, learn how to connect it to github or bitbucket and always push before trying out any complicated commands. I learned this the hard way (things deleted from the command line or git do not just get moved to the recycling bin, they are really deleted). But other than that just knowing the basics makes development so much easier compared to the days of “Script 1”, “Script 2”, “Script old”, “Script bla bla bla”, “Script bla bla bla 2”. I cringe at the thought.
Thank you for recommending so many useful tutorials to me! I finally understand git(not fully, but definitely more than I did when I created this thread). I always got stuck at the git add . part but now I understand why I couldn’t get past that stage. It’s because I forgot to cd (location of my file) so it always ended up adding all of my files in the desktop and hence it crashed each time.
After having to set up react, I finally understand more about how to use my terminal and make use of the git commands I know. Thank you so much to those who have replied! I’m going to be checking out the resources soon
Don’t feel stupid! Git is complicated when you start because it is usually
a different kind of thought process than you are used to. I had a pretty
difficult time when I first started using it, and you ABSOLUTELY need to
know it to get a job or freelance. I tried tons of different sites, courses,
videos, etc., trying to learn it.
I finally was able to learn it well enough to be comfortable through this course:
After you understand the commands and how it works, you can then use a GUI like:
If you want to Git more in depth, try this course:
I hope this helps!
Also, I saw that you mentioned Udacity. I would strongly advise you NOT to use that site.
There are tons of issues with Udacity’s courses that I have found and also read about
from other professionals, so save your money. If you know which courses to pick on Udemy,
you will never need to use another site. I like to pay for a course once, and not a monthly fee
to access multiple courses.
If this would help, a friend of mine recommended this Tutorial
That isn’t something for beginners though: that’s Git Flow, it’s for large projects with multiple developers, and it’s a massive pain in the ass to get right (involves widespread use of
git rebase, which is not something you want to be dealing with as a beginner [or imo, ever]). It exists to provide multiple levels of redundancy and safety for teams where multiple developers are working on separate features for projects at the same time. It’s not necessary if you’re a beginner with Git; it doesn’t make anything easier, makes small projects much more complex, and adds a lot of ceremony
Those are a lot of good resources everyone. I made this for myself when I was learning - perhaps it can be helpful to someone else. Feel free correct any mistakes if I made any. Or if anyone wants to suggest additions or changes.
How to use github command line Useful commands: git --help git --version git init (initialize repo locally) git add <filename> (adds <filename> to staging) git status (shows current status) git diff (shows changes since last commit) git commit -m "<message>" git push <remote> <branch> git config --global user.name "<Your Name>" (changes config file) git config --global user.email "<email@example.com>" (changes config file) git remote add origin "<URL HERE>" (for adding a new remote) git remote set-url origin <URL from github.com repo> (for setting the remote) git remote -v (verifies the remote URL) git branch <branch name> (creates a new branch) git checkout <branch name> (work with branch name) git pull <remote> <branch> (merges any changes to your local repo) git branch -d <branch> (delete a branch) touch .gitignore (create .gitignore file) echo '<filename>' >> .gitignore (to add folders or files to the .gitignore file) git fetch --all (This will pull from origin repo) git reset --hard <remote>/<branch_name> (this will overwrite all local changes) --for explanation see https://forum.freecodecamp.org/t/override-local-files-with-git-pull/13216/2 How to create a repo locally and push it to github: Step 1: git init (use in a folder to initialize a repo locally) Step 2: git add <filename> (add <filename> to staging area for next commit) or git add . (adds all files to staging) Step 3: git commit -m "<message>" (commits files in staging) Step 4: go to the github website and create a repo Step 5: get the 'cloning' url from the quick setup area by copying the url or get the 'cloning' url by click the green 'clone or download' button in the repo and copy the url Step 6: git remote add origin <URL from github> (get the url after creating repo, and next page copy the url - origin = remote name so we know what repo to commit to) Step 7: git push origin master (origin=remote master=branch) How to fork a repo and pull it from github: Step 1: go to a repo you want to fork and click the fork button at the top right (this will fork it to your account) Step 2: go to your account/newly forked repo and click the green 'clone or download' button and the copy URL button Step 3: git clone <URL you copied from step 2> (now its copied to your computer and linked to the forked repo on your account) Step 4: copy the URL from the original repo you forked by going to the repo and clicking the green 'clone or download' button and the copy button Step 5: git remote add upstream <URL you copied from step 4> (this adds a remote to the original repo to pull in changes made there) (you can name this remote connection anything you want - people often use 'upstream') If you have pushed changes to a branch, you will want to make a pull request to get your changes merged with the original repo: Step 1: go to your repo and click create pull request Step 2: fill in the info and make the request After your changes are merged with the original repo, you want to merge that repo with your forked one again: Step 1: git checkout <branch of original repo> (work with the branch you want to merge 'into') Step 2: git merge <branch> (tell git what bring you want to merge 'in') Step 3: git branch -d <branch> (clean up by deleting the old branch no longer needed since it has been merged to the original) Step 4: git push <remote> --delete <branch> (delete the branch on your fork) Maintaining Your Fork Now that you have a copy of your fork, there is work you will need to do to keep it current. Rebasing from Upstream Do this prior to every time you create a branch for a PR: //This is specific for the freecodecamp repo - replace staging with whatever branch youre working with - and upstream with another remote if you have one - Make sure you are on the staging branch $ git status On branch staging Your branch is up-to-date with 'origin/staging'. - If your arent on staging, resolve outstanding files / commits and checkout the staging branch $ git checkout staging - Do a pull with rebase against upstream $ git pull --rebase upstream staging - This will pull down all of the changes to the official staging branch, without making an additional commit in your local repo. (Optional) Force push your updated staging branch to your GitHub fork $ git push origin staging --force This will overwrite the staging branch of your fork. Check this URL for a visual on github repos https://guides.github.com/introduction/flow/ Created from the 'git-it' workshop Check out the lessons here: http://jlord.us/git-it/
A basic knowledge of Git is pretty much essential to a professional developer, although I think that understanding what git is and how it works is much more important than knowing the commands. I actually avoid using the command line and instead use a GUI, it allows me to visualize everything that is going on much better. If you are interested, I use Tower:
Also - this is an earlier thread on this topic that has lots of helpful information - I don't understand Git and GitHub
If you have no experience with using version control systems or you used SVN before, take a look at this blog post which briefly discusses the most important features of Git that you need to know at the beginning.